This is a popular re-post from my old Blogger blog.
I’m working on a website up-time monitoring script.
After I had my initial prototype working, I received more requirements for logging output to CSV in addition to storing output in Access DB and decided to add CPU usage percentages to the logging.
Once I had all that done, I started getting odd errors when solution should be detecting a down-time event.
Testing the script with older version of Microsoft.XmlHttp had issues where certain but not all websites the script would call were incorrectly displaying HTTP status code 404 but a 200 OK was really sent back verified by using Fiddler. Very odd behavior.
The error is related to VBScript’s use of the older version of the Microsoft.XmlHttp object.
The Code
Function isPortalOffline(strURL)
'Set WshShell = WScript.CreateObject("WScript.Shell")
Set http = CreateObject("Microsoft.XmlHttp")
http.open "GET", strURL, False
http.send
'Only check for error of the http Get request
if err.Number <> 0 Then
isPortalOffline = True
Else
'Wscript.Echo "error" & Err.Number & ": " & Err.Description
isPortalOffline = False
End If
'Clear the error after setting isPortalOffline
err.clear
'set WshShell = Nothing
Set http = Nothing
ReportError("isPortalOffline")
End Function
Error: MSXML3.dll error ‘800C0005’ The System cannot locate the resource
Changed MSXML Objects.
The Fixed Code
Replaced Microsoft.XmlHttp with MSXML2.ServerXMLHTTP.
Function isPortalOffline(strURL)
'Set WshShell = WScript.CreateObject("WScript.Shell")
Set http = CreateObject("MSXML2.ServerXMLHTTP")
http.open "GET", strURL, False
http.send
'Only check for error of the http Get request
if err.Number <> 0 Then
isPortalOffline = True
Else
'Wscript.Echo "error" & Err.Number & ": " & Err.Description
isPortalOffline = False
End If
'Clear the error after setting isPortalOffline
err.clear
'set WshShell = Nothing
Set http = Nothing
ReportError("isPortalOffline")
End Function
This resolved my issues!
I hope this helps someone. 🙂