Windows Vista Forums

verify that a web page loaded

  1. #1


    hb21l5 Guest

    verify that a web page loaded

    I'm creating a script that will automatically check a number items on our
    network.
    ping servers, services are running, web page loads ok etc.

    I've got most of this sorted, but I'm not sure if this part is possible, I
    want to create vb script that can check if a URL will load successfully.

    Is there any way to do that in VB script?



    cheers
    Dave

      My System SpecsSystem Spec

  2. #2


    gimme_this_gimme_that Guest

    Re: verify that a web page loaded

    I use three scripts to confirm that a site is responding.

    Script 1 runs at 0,5,10...,55 minutes on the hour.

    Script 1 sets things up for script 2.
    Script 2 sets things up for script 3.


    Here is script 1: It removes a tag file.

    ----------------
    On Error Resume Next
    Set fs = CreateObject("Scripting.FileSystemObject")
    fs.DeleteFile("c:\_myserver_myport.txt")
    set fs = Nothing
    -------------

    Script 2 fetches the HTML on http://myserver:myport

    When the site responds or if the page renders in less than 12 seconds
    a tag file, C:\myserver_myport.txt, is created.

    When the site is not responding or is responding slowly the tag file
    is not created.

    Script 2 runs on 1,6,11,...56 on the hour.

    ----
    dim oHTTP, bRespReceived, iTimeout, httpStatus, t

    On Error Resume Next

    ''Global Variables
    bRespReceived = False
    iTimeout = 0
    t = now
    URL = "http://myserver:myport"

    upDown = "Down"

    'Subs and Functions
    Sub RespReceived
    If oHTTP.readystate = 4 Then
    bRespReceived = True
    End If
    End Sub

    Function TimedOut
    Set oHTTP = WScript.CreateObject("Microsoft.XMLHTTP")
    oHTTP.onreadystatechange = GetRef("RespReceived")
    oHTTP.open "GET", URL, False
    oHTTP.send
    upDown = "Up"
    httpStatus = False
    Do while bRespReceived = False
    iTimeout = iTimeout + 1
    if datediff("s",t,now) > 12 then
    httpStatus = True
    oHTTP.abort
    on error goto 0
    exit Do
    end if
    Loop
    TimedOut = httpStatus
    End Function

    'Main

    Set fs = CreateObject("Scripting.FileSystemObject")

    If false = TimedOut() And upDown = "Up" Then
    set file = fs.OpenTextFile("c:\_myserver_myport.txt", 2, "true")
    file.close()
    Else
    'Do Nothing
    end if

    Set fs = Nothing


    ------------

    Script three runs at 2,7,9,... 57 on the hour.

    It checks for the tag file and when it does not exist, it sends an
    email message to stake holders.

    -----------
    Sub Notify()
    Set msg = CreateObject("CDO.Message")
    msg.Subject = "http://myserver:myport is timing out or is down"
    msg.From = "gimme_this_gimme_that@xxxxxx"
    msg.To = "gimme_this_gimme_that@xxxxxx"
    msg.TextBody = "This message was sent from an automated script."
    msg.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/
    configuration/sendusing") = 2
    msg.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/
    configuration/smtpserver") = "gimmes_smtpserver"
    msg.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/
    configuration/smtpserverport") = 25
    msg.Configuration.Fields.Update
    msg.Send
    End Sub

    On Error Resume Next

    Set fs = CreateObject("Scripting.FileSystemObject")

    If fs.FileExists("C:\_myserver_myport.txt") Then
    '' Do Nothing
    Else
    Notify()
    End If
    Set fs = Nothing


    ---

    This is a barebones implementation. If you want take these scripts to
    the next level - where you examine the HTML page for specific text,
    you would add logic to fetch the HTML and parse it. Then after that
    you could modify the script so that response times get persisted to a
    database, or whatever.

    It's a little tricky setting things up with Task Scheduler - but if
    you read my recent posts on this news group you'll find tips on how
    to do it.

      My System SpecsSystem Spec

verify that a web page loaded

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I verify? Antihiatus Gaming 7 30 Jul 2009
won't verify acct Meg Vista mail 4 17 Jul 2008
Verify COA Rob Vista installation & setup 5 06 Sep 2007
Using SHA to verify Download =?Utf-8?B?Qm9i?= Vista installation & setup 1 14 Sep 2006
windows cannot verify cd key DaMulta Vista installation & setup 0 09 Jun 2006