Visual Basic 6 – Silent Ping Function

Send Us a Sign! (Contact Us!)
--> (Word) --> (PDF) --> (Epub) --> (Text)
--> (XML) --> (OpenOffice) --> (XPS)

SCENARIO

Can any one supply me with some VB6 code to perform a silent PING.

By silent I mean, no DOS screens to appear and the PING is performed in the background without the user being aware.

The code also needs to capture the output and I do not require any thing fancy, just some simple code to PING from one PC to another, on a network.

Function PingSilent(strComputer)
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address = '" & strComputer & "'")
For Each objStatus in objPing
If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then
'WScript.Echo("Computer " & machine & " is not reachable")
PingSilent = 0
Else
'WScript.Echo("Computer " & machine & " is Live")
PingSilent = 1
End If
Next
End Function

USAGE

You will have to call this function in the following way:

PingSilent("172.16.0.25")

Usually you can use it in an IF clause:

If PingSilent("172.16.0.25") = 0 Then
Else
End If

SOURCE

LINK (andreavb.com)

LANGUAGE
ENGLISH