Ping and win32_pingrequest - nos. of Echo Request messages sent

R

RD

I'm planning to modify existing scripts which check whether system is alive.
I'm thinking of using win32_PingStatus instead of ping.exe. However I
couldn't find one option in WMI object which ping.exe uses and that is "-n
Count : Specifies the number of Echo Request messages sent. The default is
4.". I couldn't find matching property in wmi object. Does win32_pingstatus
uses count= 1? Can I invoke object in VBScript more than one time to
increment the nos. of echo request sent.

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
 
R

RD

I found another issue with buffersize. On a win2k8 EE 64-bit server in LAN,
if I ping a server, which is powered off, this is what I see.

--------
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?
 
D

DCJ

If you are checking that the system is 'alive' and responding why do
you need to ping more than once?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top