Dim sHost 'name of Windows XP computer from which the PING command will be initiated
Dim sTarget 'name or
IP address of remote computer to which connectivity will be tested
Dim cPingResults 'collection of instances of Win32_PingStatus class
Dim oPingResult 'single instance of Win32_PingStatus class
sHost = "SWYNKPC-XP001"
sTarget = "192.168.12.14"
Set cPingResults = GetObject("winmgmts:{impersonationLevel=impersonate}//" & _
sHost & "/root/cimv2"). ExecQuery("SELECT * FROM Win32_PingStatus " & _
"WHERE Address = '" + sTarget + "'")
For Each oPingResult In cPingResults
If oPingResult.StatusCode = 0 Then
If LCase(sTarget) = oPingResult.ProtocolAddress Then
WScript.Echo sTarget & " is responding"
Else
WScript.Echo sTarget & "(" & oPingResult.ProtocolAddress & ") is responding"
End If
Wscript.Echo "Bytes = " & vbTab & oPingResult.BufferSize
Wscript.Echo "Time (ms) = " & vbTab & oPingResult.ResponseTime
Wscript.Echo "TTL (s) = " & vbTab & oPingResult.ResponseTimeToLive
Else
WScript.Echo sTarget & " is not responding"
WScript.Echo "Status code is " & oPingResult.StatusCode
End If
Next