Results 1 to 7 of 7
  1. #1
    Richardsmith is offline Member
    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0

    Default Remote Windows Login

    Hello all,

    I'm building a little java app for controlling computers on my work's computer classes.
    It is quite easy for me to start/restart and power up the computers, but I don't know how to login the computers.
    Do you happen to know a code I might use?

    We are running Windows 7 with active directory.

    Richard

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,776
    Rep Power
    5

    Default Re: Remote Windows Login

    ... really? You can make computers power on remotely using Java? Amazing!
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    926
    Rep Power
    2

    Default Re: Remote Windows Login

    Quote Originally Posted by gimbal2 View Post
    ... really? You can make computers power on remotely using Java? Amazing!
    I don't want to sound pedantic, but you can: just craft a proper Wake-on-Lan packet. I haven't tested this, but it looks like it does what it says on the box. A WoL packet is 6 times the MAC address so it looks legit :)

    Source: Simple Java Implementation of Wake-on-LAN

    Java Code:
    import java.io.*;
    import java.net.*;
    
    public class WakeOnLan {
        
        public static final int PORT = 9;    
        
        public static void main(String[] args) {
            
            if (args.length != 2) {
                System.out.println("Usage: java WakeOnLan <broadcast-ip> <mac-address>");
                System.out.println("Example: java WakeOnLan 192.168.0.255 00:0D:61:08:22:4A");
                System.out.println("Example: java WakeOnLan 192.168.0.255 00-0D-61-08-22-4A");
                System.exit(1);
            }
            
            String ipStr = args[0];
            String macStr = args[1];
            
            try {
                byte[] macBytes = getMacBytes(macStr);
                byte[] bytes = new byte[6 + 16 * macBytes.length];
                for (int i = 0; i < 6; i++) {
                    bytes[i] = (byte) 0xff;
                }
                for (int i = 6; i < bytes.length; i += macBytes.length) {
                    System.arraycopy(macBytes, 0, bytes, i, macBytes.length);
                }
                
                InetAddress address = InetAddress.getByName(ipStr);
                DatagramPacket packet = new DatagramPacket(bytes, bytes.length, address, PORT);
                DatagramSocket socket = new DatagramSocket();
                socket.send(packet);
                socket.close();
                
                System.out.println("Wake-on-LAN packet sent.");
            }
            catch (Exception e) {
                System.out.println("Failed to send Wake-on-LAN packet: + e");
                System.exit(1);
            }
            
        }
        
        private static byte[] getMacBytes(String macStr) throws IllegalArgumentException {
            byte[] bytes = new byte[6];
            String[] hex = macStr.split("(\\:|\\-)");
            if (hex.length != 6) {
                throw new IllegalArgumentException("Invalid MAC address.");
            }
            try {
                for (int i = 0; i < 6; i++) {
                    bytes[i] = (byte) Integer.parseInt(hex[i], 16);
                }
            }
            catch (NumberFormatException e) {
                throw new IllegalArgumentException("Invalid hex digit in MAC address.");
            }
            return bytes;
        }
        
       
    }
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  4. #4
    Richardsmith is offline Member
    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0

    Default Re: Remote Windows Login

    Yes!
    But it would be even more amazing if I can manage my computer to fix me a cup of coffee...

  5. #5
    Richardsmith is offline Member
    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0

    Default Re: Remote Windows Login

    Thanks SurfMan!

    Is this code to wake up the computer after shutdown or log in to windows?...

  6. #6
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    926
    Rep Power
    2

    Default Re: Remote Windows Login

    This code is to wake up the computer when it's powered off, if it supports Wake-on-Lan (WoL).

    Maybe you can google for an RDP implementation in Java. NTLM authentication is another subject for authentication to Windows servers. I am not familiar with any of those.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  7. #7
    Richardsmith is offline Member
    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0

    Default Re: Remote Windows Login

    Quote Originally Posted by SurfMan View Post
    This code is to wake up the computer when it's powered off, if it supports Wake-on-Lan (WoL).

    Maybe you can google for an RDP implementation in Java. NTLM authentication is another subject for authentication to Windows servers. I am not familiar with any of those.
    OK, thanks. Your code does help since I don't have to use the program I found fort startup.
    I hope I'll find the code for login.

Similar Threads

  1. Login system: multiple windows
    By D-Dog in forum New To Java
    Replies: 2
    Last Post: 04-10-2012, 03:18 PM
  2. Problem when the same user login in different windows
    By murali23krishna in forum JavaServer Faces (JSF)
    Replies: 1
    Last Post: 04-07-2012, 06:19 AM
  3. Connect to remote Windows machine using JAVA on Linux
    By sumukh_death in forum Networking
    Replies: 6
    Last Post: 09-23-2011, 06:23 PM
  4. setWindowOpaque causes problems at windows login.
    By fwilliams in forum AWT / Swing
    Replies: 2
    Last Post: 06-29-2010, 02:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •