' NAME: 1EWakeup.vbs ' ' AUTHOR: alan dot kaplan at va dot gov, Dept. Veterans Affairs, VISN 6 ' DATE : 8/23/2011 ' ' COMMENT: Wake up a computer using 1E ' Edit default SCCMServer ' you can run this interactively by clicking on script ' command line cscript 1EWakeup.vbs NetBIOSName2Wake [SCCMServer] '========================================================================== Option Explicit Dim strSCCMServer, strComputer Dim bBatch Dim oWMI 'Edit for default SCCM Wakeup Server! strSCCMServer = "YOUR1ESCCMSERVER" dim wshShell: Set wshShell = WScript.CreateObject("WScript.Shell") Dim PingReply If (Not IsCScript()) Then 'If not CScript, re-run with cscript... dim quote: quote=chr(34) Dim strCmdLine, Argument strCmdLine = WScript.Path & "\cscript.exe //NOLOGO " & quote & WScript.scriptFullName & Quote If Wscript.Arguments.Count > 0 Then For Each Argument in Wscript.Arguments strCmdLine = strCmdLine & space(1) & quote & Argument & quote Next End If wshShell.Run strCmdLine,1,False WScript.Quit '...and stop running as WScript End If If WScript.Arguments.Count >0 Then bBatch = True strComputer = WScript.Arguments(0) If WScript.Arguments.Count = 2 Then strSCCMServer = WScript.Arguments(1) Else strComputer = InputBox("Enter the NETBIOS name of the 1E client to wake?", "Computer to Wake") If strcomputer = "" Then WScript.Quit strSCCMServer = InputBox("Enter the name of your SMS Wakeup Server","Server Name",strSCCMServer) End If strComputer = UCase(strComputer) WaitForReply 1 If PingReply Then WScript.Echo strComputer & " online, quitting" WScript.Sleep 5000 WScript.Quit(0) End If WScript.Echo "Ping failed, requesting wakeup for " & strComputer & " on SMS Server " & strSCCMServer WakeComputer() 'Ping for 2 minutes before quitting WaitForReply 120 If PingReply Then WScript.Sleep 5000 WScript.Quit(0) Else WScript.Echo strComputer & " failed to wake" WScript.Sleep 5000 WScript.Quit (100) End If Sub WakeComputer() 'This is a modification of a script by Reto Egeter from ' http://www.myitforum.com/forums/tm.aspx?high=&m=216530&mpage=1 Dim locator: Set locator = CreateObject("WbemScripting.SWbemLocator") Dim services: Set services = locator.ConnectServer(strSCCMServer, "root\N1E\WakeUp") If Err <> 0 Then WScript.Echo "Failed to connect to " & strSCCMServer & Space(1) & Err.Description WScript.Quit(500) End If WScript.Echo "Sending wake packet" Dim WakeService: Set WakeService = services.Get("WakeUp") WakeService.WakeName strComputer WScript.Echo "Sent." End Sub Sub WaitForReply(iPingCount) Dim i Dim iSleep :iSleep = 1 'delay in seconds between pings. 'Convert time between ping to sleep units iSleep = iSleep * 1000 'Connect to local system WMI for ping provider Set oWMI = GetObject("winmgmts:\\.\root\CIMV2") If Err <> 0 Then MsgBox "WMI error from local computer", vbCritical + vbOKOnly,"Error" WScript.Quit(200) End If For i = 0 To iPingCount -1 Ping(strComputer) WScript.Sleep iSleep If PingReply Then WScript.Echo vbTab & strComputer & " online" Exit For End If Next End Sub Function Ping(strComputer) PingReply = False Dim strQuery, colItems, objItem wscript.Echo " Pinging " & strComputer 'Note syntax in query to get address and resolved name strQuery = "SELECT * FROM Win32_PingStatus where address = '" & strComputer & "'" Set colItems = oWMI.ExecQuery(strQuery,,48) For Each objItem In colItems If objItem.statusCode=0 Then PingReply = True Next End Function Function IsCScript() If (InStr(UCase(WScript.FullName), "CSCRIPT") <> 0) Then IsCScript = True Else IsCScript = False End If End Function