VBScript: When You Can’t Use Powershell to Ping a Webpage…

Sometimes, there’s a need to schedule a “ping” to a webpage (that needs to be pre-compiled, for instance). While using PowerShell is the easiest way to do this, it’s not always available on older server, while VBScript is nearly always a safe bet. The biggest issue with using VBScript or the command line is what to do with the window it may open. Instead of using iexplore and taskkill, using the following VBScript is my fav alternative.

Call pingPage ("http://www.domain.com")

Function pingPage (strURL)
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")

objXMLHTTP.open "GET", strURL, false

If objXMLHTTP.Status <> 200 Then
'email someone about it
End if

Set objXMLHTTP = Nothing
End Function

On a related note: the PowerShell line looks something like this: $pingPage = (new-object net.webclient).DownloadString(“http://www.domain.com”)

Chrissy is a PowerShell MVP who has worked in IT for nearly 20 years, and currently serves as a Sr. Database Engineer in Belgium. Always an avid scripter, she attended the Monad session at Microsoft’s Professional Developers Conference in Los Angeles back in 2005 and has worked and played with PowerShell ever since. Chrissy is currently pursuing an MS in Systems Engineering at Regis University and helps maintain RealCajunRecipes.com in her spare time. She holds a number of certifications, including those relating to SQL Server, SuSE Linux, SharePoint and network security. She recently became co-lead of the SQL PASS PowerShell Virtual Chapter. You can follow her on Twitter at @cl.

Posted in PowerShell, VBScript
One comment on “VBScript: When You Can’t Use Powershell to Ping a Webpage…
  1. frankCBA says:

    Havn’t thought about it before..but why not?! thx ;-)

Leave a Reply

Your email address will not be published. Required fields are marked *