Script Tips

Knock, Knock, But No One's Home

Quick way to check out why a Web page isn't responsive.

One thing administrators often have to worry about is bad links on a Web page, or even a Web server that isn’t responding. VBScript can give you a quick solution for checking a particular Web page (and thus the server), by using the Microsoft XMLHTTP object.

Using it is simple:

sTestURL = "http://www.scriptinganswers.com"
Set oHTTP = CreateObject("MSXML2.XMLHTTP")
Call oHTTP.Open("GET", sTestURL, False)
oHTTP.Send
If oHTTP.Status <> 202
  WScript.Echo "Couldn’t reach URL; error: " & oHTTP.Status
Else
  WScript.Echo "URL pinged successfully"
End If

You can also access oHTTP.ResponseText to get the contents of the Web page you retrieved. This is a fast and easy way to quickly check a Web page or even an entire Web server. (If the server can’t return a page that is known to exist, such as index.htm, then the server itself may be down.) You could extend the script to quickly check several servers at once, giving you a snapshot status of an entire Web farm.

Using oHTTP.ResponseText allows you to check the actual contents of the Web page you retrieved. You could then use string-handling functions to check the Web page for specific content (such as using InStr() to see if the page contained a particular word). The XMLHTTP object is just one of many COM objects built into Windows that VBScript can leverage to perform useful administrative tricks.

About the Author

Don Jones is a multiple-year recipient of Microsoft’s MVP Award, and is an Author/Evangelist for video training company Pluralsight. Don is also a co-founder and President of PowerShell.org, a community dedicated to Microsoft’s Windows PowerShell technology. Don has more than two decades of experience in the IT industry, and specializes in the Microsoft business technology platform. He’s the author of more than 50 technology books, an accomplished IT journalist, and a sought-after speaker and instructor at conferences worldwide. Reach Don on Twitter at @concentratedDon, or on Facebook at Facebook.com/ConcentratedDon.

comments powered by Disqus

Redmond Tech Watch

Sign up for our newsletter.

I agree to this site's Privacy Policy.