Automatically reboot an unresponsive Windows Server
February 5, 2009 by: B.HardingMy servers are leased so if anything goes wrong and a reboot is needed I have to wait for my provider to preform it.
In this post we will create a vb Script that pings an IP address and reboots if it can’t see it. We will simply run it on a timer using the command scheduler.
Here is the script:
Option Explicit
dim strHost
‘The ip address you want to monitor
strHost=”111.222.333.444″
if Ping(strHost) = True then
‘You can do stuff here if you want.
Else
‘The next three lines reboot
dim objShell
Set objShell = CreateObject(“WScript.Shell”)
objShell.Run “shutdown /r /t 000″
end if
‘the following is a subroutine called above
Function Ping(strHost)
dim objPing, objRetStatus
set objPing = GetObject(“winmgmts:{impersonationLevel=impersonate}”).ExecQuery(“select * from Win32_PingStatus where address = ‘” & strHost & “‘”)
for each objRetStatus in objPing
if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
Ping = False
else
Ping = True
end if
next
End Function
Just save this to a vbs file and add
cscript c:\ping.vbs
to “Scheduled tasks” every 15 minutes.
‘Till next time…



Other variant is possible also
Very good piece of content, this is very similar to a site that I have. Please check it out sometime and feel free to leave me a comenet on it and tell me what you think. I’m always looking for feedback.