I'm sure this code used to work but I can't force a false positive.
In summary, the code opens IE and navigates to a URL. The If...ElseIf..EndIf loop (immediately after the [tt]wscript.echo objIE.Document.Body.innerHTML[/tt] line, which - and this MUST be a clue - produces no output) is meant to check the contents of the resulting page to see if the connection was established.
The first two tests in that ElseIf allow for different versions of IE using different wordings to their error pages, one of which should have picked up the contents of a local html file saved from a forced error page (by removing the network cable, surfing to a URL and doing Save As!). The third test checks for spaces in the code which really ought to flag up an error under ANY conditions!!
What needs to be changed?
JJ
[small][purple]Variables won't. Constants aren't[/purple]
There is no apostrophe in the plural of PC (or PST, or CPU, or HDD, or FDD, and so on)[/small]
In summary, the code opens IE and navigates to a URL. The If...ElseIf..EndIf loop (immediately after the [tt]wscript.echo objIE.Document.Body.innerHTML[/tt] line, which - and this MUST be a clue - produces no output) is meant to check the contents of the resulting page to see if the connection was established.
The first two tests in that ElseIf allow for different versions of IE using different wordings to their error pages, one of which should have picked up the contents of a local html file saved from a forced error page (by removing the network cable, surfing to a URL and doing Save As!). The third test checks for spaces in the code which really ought to flag up an error under ANY conditions!!
Code:
Sub CheckInternet(strTestURL)
Dim strInternetError
If gbDebug = True then
wscript.echo "18"
End If
Set objIE = wscript.CreateObject("InternetExplorer.Application","objIE_")
If Err.Number <> 0 Then
On Error GoTo 0
Msg = "IE application not found."
MsgBox Msg,vbExclamation,strAppDescription
Wscript.Quit
End If
On Error GoTo 0
objIE.visible = false 'true
objIE.ToolBar = 0
objIE.statusbar=false
objIE.Navigate "about:blank"
Do Until objIE.ReadyState = 4
WScript.Sleep 100
Loop
objIE.Navigate strTestURL
Do While objIE.Busy = True
WScript.Sleep 500
Loop
' [URL unfurl="true"]http://www.tek-tips.com/viewthread.cfm?qid=1383115&page=1[/URL] refers to
' following loops
'WScript.Sleep 500
do while objIE.Document is nothing
wscript.sleep 50
loop
do while objIE.Document.body is nothing
wscript.sleep 50
loop
wscript.echo objIE.Document.Body.innerHTML
If InStr(objIE.Document.Body.innerHTML, "The Web site might be experiencing technical difficulties") > 0 then
wscript.echo " Unable to connect to " & strTestURL & "."
BuildTable(conRed & "Unable to connect to " & strTestURL & conBlack)
ElseIf InStr(objIE.Document.Body.innerHTML, "Internet Explorer cannot display the webpage") > 0 Then
wscript.echo " Unable to connect to " & strTestURL & "."
BuildTable(conRed & "Unable to connect to " & strTestURL & conBlack)
ElseIf InStr(objIE.Document.Body.innerHTML, " ") > 0 Then
wscript.echo " Unable to connect to " & strTestURL & "."
BuildTable(conRed & "Unable to connect to " & strTestURL & conBlack)
Else
strInternetError=False
wscript.echo " Tested connectivity to " & strTestURL & " OK."
BuildTable("Connection OK to " & strTestURL)
End If
objIE.quit
Set ObjIE = Nothing
End Sub
What needs to be changed?
JJ
[small][purple]Variables won't. Constants aren't[/purple]
There is no apostrophe in the plural of PC (or PST, or CPU, or HDD, or FDD, and so on)[/small]