Thursday 6 April 2017

VBS script to check if a site is up and running






Dim strWebsite

strWebsite = "www.sccmrookie.blogspot.com"

If PingSite( strWebsite ) Then
    WScript.Echo "Web site " & strWebsite & " is up and running!"
Else
    WScript.Echo "Web site " & strWebsite & " is down!!!"
End If


Function PingSite( myWebsite )
' This function checks if a website is running by sending an HTTP request.
' If the website is up, the function returns True, otherwise it returns False.
' Argument: myWebsite [string] in "www.domain.tld" format, without the
' "http://" prefix.

    Dim intStatus, objHTTP

    Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )

    objHTTP.Open "GET", "http://" & myWebsite & "/", False
    objHTTP.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MyApp 1.0; Windows NT 5.1)"

    On Error Resume Next

    objHTTP.Send
    intStatus = objHTTP.Status

    On Error Goto 0

    If intStatus = 200 Then
        PingSite = True
    Else
        PingSite = False
    End If

    Set objHTTP = Nothing
End Function

0 commenti:

Post a Comment

Give me you feedback!