Would following code be similar to ping -n 4 ...
for i=0 to 3 ' Defualt echo request in ping.exe is 4.
GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select * from Win32_PingStatus where Address = strhost ...)
Next
--------
C:\ping -n 1 -l 0 172.17.103.55
Pinging 172.17.103.55 with 0 bytes of data:
Reply from 172.17.103.168: Destination host unreachable.
Ping statistics for 172.17.103.55:
Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
---------
However when I called win32_PingStatus with BufferSize=0, I got StatusCode
equal to zero. My vbscript looks like this.
nBufSize = 0
WQL = "SELECT * FROM Win32_PingStatus WHERE BufferSize = " & nBufSize & "
AND Address = '" & strHost & "'"
set objPing =
GetObject("winmgmts:impersonationLevel=impersonate}").ExecQuery(WQL)
for each objRetStatus in objPing
Wscript.Echo "BufferSize : " & objRetStatus.BufferSize ' This is 0
objRetStatus.StatusCode 'this is 0 (zero) - success
next
But with nBufsize set to 1, the StatusCode is 11003 which is correct. I
wonder why statuscode is 0 if Bufsize is 0.
Does any one know if BufSize is same as "-l' option of ping.exe?
Does any one run into this issue?
I tend to stick with the defaults and check whether a reply is
received at all (example below). If there's no reply then the
ReplySize will be Null. You could compare the ReplySize to the
BufferSize if you want to try and check the quality of the connection
in some way but it would probably have very limited value.
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
ExecQuery("SELECT ReplySize FROM Win32_PingStatus WHERE address = '" &
strHost & "' ")
For Each objStatus in objPing
If Not IsNull (objStatus.ReplySize) Then
' Report that the system is responding
' Wscript.echo objStatus.ReplySize
End If
Next
I wonder if in your example you get a StatusCode of 0 because you have
successfully sent and received 0 bytes.
Domini