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
| Option Explicit
Dim ws
Set ws = CreateObject("wscript.shell")
If IsOnLine("www.google.fr") Then
ws.run "calc.exe"
Else
ws.run "Notepad.exe"
End If
'**************************************************************************************
Function IsOnLine(strHost)
Dim objPing,i,objRetStatus,PingStatus
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select * from Win32_PingStatus where address = '" & strHost & "'")
i = 0
Do
i = i + 1
For Each objRetStatus In objPing
If IsNull(objRetStatus.StatusCode) Or objRetStatus.StatusCode <> 0 Then
PingStatus = False
Else
PingStatus = True
End If
Next
wscript.sleep 200
If i = 4 Then Exit Do
Loop until PingStatus = True
If PingStatus = True Then
IsOnLine = True
Else
IsOnLine = False
End If
End Function
'*************************************************************************************** |