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 = ""
Set oHTTP = CreateObject("MSXML2.XMLHTTP")
Call oHTTP.Open("GET", sTestURL, False)
If oHTTP.Status <> 202
  WScript.Echo "Couldn’t reach URL; error: " & oHTTP.Status
  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

With more than fifteen years of IT experience, Don Jones is one of the world’s leading experts on the Microsoft business technology platform. He’s the author of more than 35 books, including Windows PowerShell: TFM, Windows Administrator’s Scripting Toolkit, VBScript WMI and ADSI Unleashed, PHP-Nuke Garage, Special Edition Using Commerce Server 2002, Definitive Guide to SQL Server Performance Optimization, and many more. Don is a top-rated and in-demand speaker and serves on the advisory board for TechMentor. He is an accomplished IT journalist with features and monthly columns in Microsoft TechNet Magazine, Redmond Magazine, and on Web sites such as TechTarget and Don is also a multiple-year recipient of Microsoft’s prestigious Most Valuable Professional (MVP) Award, and is the Editor-in-Chief for Realtime Publishers.

comments powered by Disqus

Reader Comments:

Wed, Apr 27, 2005 Dennis Beaverton Oregon

I tried this too and got the error. changed it - and am a happy camper...

Tue, Apr 26, 2005 Cary McDonald Anonymous

This was cool. I changed the following for verifying that it was sucessful or access was denied to a page that required authentication
if status = 200 or 401 then

I also added an else statment to display the oHTTP.Status if it was not equal to 200 or 401 so I would know what the error being returned was.


Mon, Apr 25, 2005 Rhys Anonymous

I tried this, and guess what? I got an error that the URL couldn't be reached, error: 200. I checked the URL, copied it into IE, and sure enough was able to load the page. I then changed the URL in the code to something non-existant, and got an error 502. I changed the code to " 200" and was able to receive a 'success' message. Are there any references to what these values mean? I'm uncomfortable tweaking numbers like this just to make them work - I wouldn't want to rely on 200 as a success message without knowing why there is a discrepancy. Thanks!

Add Your Comment Now:

Your Name:(optional)
Your Email:(optional)
Your Location:(optional)
Please type the letters/numbers you see above

Redmond Tech Watch

Sign up for our newsletter.

I agree to this site's Privacy Policy.