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
I would love to be able to get this to work
ReplyDeleteWhen prompted for HOST PC I put in the host machine name
MAC
I put in the mac address of the machine I want to wake up
IP
I put in the IP of the machine I want to wake up
then I get an error 0x80041003
Script C:\TEMP\WOL.vbs
Line: 29
Char: 1
at first it was
line 25
Char 1
Any ideas?
Thank you!
Have you downloaded the WOL software http://sourceforge.net/projects/wake-on-lan and extracted it to C:\temp\wol? c:\temp\WOL\bin\wol.exe is the specific file required.
DeleteAlso check that you are local admin on the Host PC.
Script: C:\temp\WOL\run.vbs
ReplyDeleteLine: 25
Char: 5
Error: Path not found
Code: 800A004C
Source: Microsoft VBScript runtime error
Hi, I'm constantly getting this error message. The path is correct, WOL files are there ... no idea why it keeps saying path not found.
Ok I have modified the script.
ReplyDeleteobjFSO.CopyFolder "WOL" to objFSO.CopyFolder "C:\temp\WOL"
It was assuming that you were running the script from c:\temp.
Hopefully it works OK for you now?
Cheers,
Steve