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)
If oHTTP.Status <> 202
WScript.Echo "Couldn’t reach URL; error: " & oHTTP.Status
WScript.Echo "URL pinged successfully"
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.
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 MCPMag.com. 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.