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 Curriculum Director for IT Pro Content 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.

Featured

  • Surface and ARM: Why Microsoft Shouldn't Follow Apple's Lead and Dump Intel

    Microsoft's current Surface flagship, the Surface Pro X, already runs on ARM. But as the ill-fated Surface RT showed, going all-in on ARM never did Microsoft many favors.

  • IT Security Isn't Supposed To Be Easy

    Joey explains why it's worth it to endure a little inconvenience for the long-term benefits of a password manager and multifactor authentication.

  • Microsoft Makes It Easier To Self-Provision PCs via Windows Autopilot When VPNs Are Used

    Microsoft announced this week that the Windows Autopilot service used with Microsoft Intune now supports enrolling devices, even in cases where virtual private networks (VPNs) might get in the way.

  • Most Microsoft Retail Locations To Shut Down

    Microsoft is pivoting its retail operations to focus more on online sales, a plan that would mean the closing of most physical Microsoft Store locations.

comments powered by Disqus

Office 365 Watch

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.