Is it possible to loop a function until an item = TRUE?
I am trying to ping a server... Once connection is established, or Ping = TRUE, then a program will execute. If connection is not established, then the ping will repeat until it is TRUE.
My code thus far is below. If TRUE, MyProgram will open. If False, the function will be called again. But this does not occur...actually nothing occurs, it just exits.
Any help is gladly appreciated. If anyone knows a more efficient way of completing this task, then please let me know. Thank you!
Function Ping
Dim oPing, oRetStatus, bReturn
Set oPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address='" & "strHost" & "'")
For Each oRetStatus In oPing
If IsNull(oRetStatus.StatusCode) Or oRetStatus.StatusCode <> 0 Then
bReturn = False
Else
bReturn = True
End If
Set oRetStatus = Nothing
Next
Set oPing = Nothing
Ping = bReturn
End Function
If Ping Then
Call MyProgram
Else
Call PingSub
End If
Sub MyProgram
Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("\\Path\To\My\Program.exe")
Set objShell = Nothing
End Sub
Sub PingSub
Call Ping
End Sub