Results 1 to 7 of 7
Thread: Remote Windows Login
- 02-20-2014, 03:19 PM #1
Member
- Join Date
- Feb 2014
- Posts
- 4
- Rep Power
- 0
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
- 02-20-2014, 05:58 PM #2
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
Re: Remote Windows Login
... really? You can make computers power on remotely using Java? Amazing!
"Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
- 02-20-2014, 06:02 PM #3
Re: Remote Windows Login
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
- 02-20-2014, 06:37 PM #4
Member
- Join Date
- Feb 2014
- Posts
- 4
- Rep Power
- 0
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...
- 02-20-2014, 06:39 PM #5
Member
- Join Date
- Feb 2014
- Posts
- 4
- Rep Power
- 0
Re: Remote Windows Login
Thanks SurfMan!
Is this code to wake up the computer after shutdown or log in to windows?...
- 02-21-2014, 12:40 AM #6
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
- 02-21-2014, 03:14 AM #7
Member
- Join Date
- Feb 2014
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
Login system: multiple windows
By D-Dog in forum New To JavaReplies: 2Last Post: 04-10-2012, 04:18 PM -
Problem when the same user login in different windows
By murali23krishna in forum JavaServer Faces (JSF)Replies: 1Last Post: 04-07-2012, 07:19 AM -
Connect to remote Windows machine using JAVA on Linux
By sumukh_death in forum NetworkingReplies: 6Last Post: 09-23-2011, 07:23 PM -
setWindowOpaque causes problems at windows login.
By fwilliams in forum AWT / SwingReplies: 2Last Post: 06-29-2010, 03:12 PM
Bookmarks