Reputation: 15538
You sometimes want to start a computer without pressing it's power button. And it can be done.. over the network using a technology called Wake on LAN (WoL).
But how can it be done in AutoHotkey?
Upvotes: 1
Views: 2087
Reputation: 6370
You could use Softperfect Network Scanner (the one that has a soccer ball for an icon) and then use AutoHotkey to send commandlines to it. You can run it portably too, so you don't even need to install anything.
netscan := "c:\program files\netscan\netscan.exe"
run, %netscan% /wol:AA:EE:73:43:BB:73
The commandline syntax for netscan is at the bottom of the docs page.
/wol:MAC sends a Wake-On-LAN magic packet to the specified MAC address and immediately exits. Example: /wol:AABBCCDDEEFF.
/wolfile:filename.txt allows you to specify a text file with MAC addresses to wake-up, e.g. /wolfile:c:\myfile.txt where the file is a plain text file containing one MAC address per line.
/wakeall sends a WOL packet to all computers configured in the WOL manager and immediately quits.
But keep in mind that you have to have the option enabled in your BIOS to enable the computer to receive a magic packet on it's NIC.
Upvotes: 0
Reputation: 15538
To wake a computer over your LAN you need to create and send a so called magic packet. All you need to know is the mac address of your target computer. Also, make sure it is properly set up for WoL.
Waking the computer can be done pretty easily using the socket library in AHK:
#include Socket.ahk ;http://pastebin.com/CtM9p4QG
WakeOnLAN("AABBCCDDEEFF") ;Example - use the mac address of your target here
ExitApp
WakeOnLAN(mac) {
magicPacket_HexString := GenerateMagicPacketHex(mac)
size := CreateBinary(magicPacket_HexString, magicPacket)
UdpOut := new SocketUDP()
UdpOut.connect("addr_broadcast", 9)
UdpOut.enableBroadcast()
UdpOut.send(&magicPacket, size)
}
GenerateMagicPacketHex(mac) {
magicPacket_HexString := "FFFFFFFFFFFF"
Loop, 16
magicPacket_HexString .= mac
Return magicPacket_HexString
}
CreateBinary(hexString, ByRef var) { ;Credits to RHCP!
sizeBytes := StrLen(hexString)//2
VarSetCapacity(var, sizeBytes)
Loop, % sizeBytes
NumPut("0x" SubStr(hexString, A_Index * 2 - 1, 2), var, A_Index - 1, "UChar")
Return sizeBytes
}
Upvotes: 2