Reset IIS if Server Does NOT Retrun 200 Status
Occasionally I have experienced a 500 server error or some other weird error in IIS when it has becomes unstable. This always seems to happen when I am not near my laptop or on the road. A simple reset of IIS always seems to do the trick, but it has always required my manual input. So, I decided to schedule a task to help with the rare occurence.
A quick search of Google did not turn up exactly what I was looking for so I wrote a quick and dirty VBScript:
On Error Resume Next
'Need a .bat file with "IISRESET" in it without quotes
ResetIIS = "c:\batches\ResetIIS.bat"
strDomain = "www.domain.com"
wscript.echo "Checking: " & strDomain
Set xml = CreateObject("Microsoft.XMLHTTP")
xml.Open "GET", "http://" & strDomain, False
xml.Send
If xml.status <> "200" Then
wscript.echo strDomain & " is throwing at server error..."
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run(ResetIIS)
Set WshShell = Nothing
Else
wscript.echo "All is well..."
End If
Set xml = NothingSo, this VBScript is set to run every 3 minutes using the Schedule Tasks. It uses XMLHTTP to do a GET for the domain. If the status returned is not a 200 status, the batch file is kicked off to reset IIS. I added a few other things to check many domains and to also send me email and SMS alerts, but the script above is a good start for any scenario.