Learn when you want, where you want with convenient online training courses. Sign up now!
Experts Exchange Solution brought to you by
"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.
On Error Resume Next
Dim strTarget, strPingResults
strTarget = "10.0.1.11" 'IP address or hostname
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshExec = WshShell.Exec("ping -n 3 -w 2000 " & strTarget) 'send 3 echo requests, waiting 2secs each
strPingResults = LCase(WshExec.StdOut.ReadAll)
If InStr(strPingResults, "reply from") Then
' WScript.Echo strTarget & " responded to ping."
' WScript.Echo strTarget & " did not respond to ping."
Set WshExec = WshShell.Exec("shutdown /r /t 1") 'reboot within 1 second
Open in new window
Set WshShell = CreateObject("WScript.Shell" )
WshShell.Run chr(34) & "c:\batchfiles\autoreboot.bat" & Chr(34), 0
Set WshShell = Nothing
REM: Reboot on Network Failure
set /a counter=0
ping google.com > %temp%\pinglog.txt
find "Reply from" < %TEMP%\pinglog.txt > nul
if errorlevel 1 (set /a counter=%counter%+1)
if not errorlevel 1 (set /a counter=0)
set /a timeout = 100 - %counter%
if %counter% GEQ 4 (echo System reboot imminent, please press ctrl-c in the next %timeout% seconds to abort)
if %counter% GEQ 100 (shutdown -r)
Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.