Below is a script which remotely executes the command on a host computer on the same subnet to send the WOL packet.
You will need
- WOL capable computer you wish to wake.
- A host machine on the same subnet as the comptuer you wish to wake.
- WOL software http://sourceforge.net/projects/wake-on-lan/ extract the software to C:\temp\wol
- MAC address of computer you wish to wake (you can get from DHCP) .
'Copy Wake on LAN files to remote computer then execute WOL
'Allows you to select remote computer on a different subnet as a host and wake another computerOption Explicit
Dim strHostComputer, strMAC, strIPComputer, objFSO
Dim objWMIService, objProcess, errReturn
Dim strComputerOn, Count, strCommand
Dim intProcessID, strComputer, colPingedComputers
Dim objComputer
strHostComputer =Inputbox("Wake Computer on another Subnet" & chr(10) & chr(13) & chr(10) & chr(13) & "Enter HOST PC Number on Remote Subnet","Input Required")
If strHostComputer = "" Then
WScript.Echo "Host blank exiting script!"
WScript.Quit
End if
strMAC =Inputbox("Enter MAC of PC you want to WAKE" & chr(10) & chr(13) & chr(10) & chr(13) & "MAC can be obtained from DHCP Scope, Address Leases","Input Required")
If strMAC = "" Then
WScript.Echo "MAC blank exiting script!"
WScript.Quit
End if
strIPComputer =Inputbox("Enter IP Address of Computer you want to WAKE","Input Required")
If strIPComputer = "" Then
WScript.Echo "IP Blank will send request but can't check progress"
End if
Const OverWriteFiles = TRUE
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("C:\temp\WOL\bin\wol.exe") Then
objFSO.CopyFolder "C:\temp\WOL" , "\\" & strHostComputer & "\C$\temp\WOL" , OverWriteFiles
Else
Wscript.Echo "Wake on Lan File C:\temp\WOL\bin\wol.exe not found. Download from http://sourceforge.net/projects/wake-on-lan"
WScript.Quit
End If
strCommand = "C:\temp\WOL\bin\wol.exe " & strMAC
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strHostComputer & "\root\cimv2")
Set objProcess = objWMIService.Get("Win32_Process")
errReturn = objProcess.Create(strCommand, null, null, intProcessID)
If errReturn = 0 Then
'WScript.Echo strHostComputer &" " & strCommand & " executed with a process ID: " & intProcessID
Else
WScript.Echo strHostComputer & " " & strCommand & " not started due to error: " & errReturn
End If
If strIPComputer = "" Then
WScript.Quit
End if
' Verify Computer Availability
Wscript.Echo "Waking Remote Computer - usually takes about 1 minute"
Count = 0
Do While strComputerOn <> 1
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPingedComputers = objWMIService.ExecQuery _
("Select * from Win32_PingStatus Where Address = '" & strIPComputer & "'")
For Each objComputer in colPingedComputers
If objComputer.StatusCode = 0 Then
Wscript.Echo "Remote Computer " & strIPComputer & " Powered On!!!"
strComputerOn=1
Else
WScript.sleep 20000
Count = Count + 1
If Count = 7 Then
Wscript.Echo "Can't Connect to Remote Machine WOL has failed :(" & chr(10) & chr(13) & chr(10) & chr(13) & "Or Remote Machine has new IP"
WScript.Quit
End if
End If
Next
Loop