Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - verify that a web page loaded

Reply
 
Old 10-24-2008   #1 (permalink)
hb21l5


 
 

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
Old 10-24-2008   #2 (permalink)
gimme_this_gimme_that


 
 

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
Reply

Thread Tools


Similar Threads
Thread Forum
How do I verify? Gaming
Can't Verify publisher Vista General
Blue Screen - Page fault in non page area Vista performance & maintenance
Verify COA Vista installation & setup


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46