win32_pingstatus

J

JV

Hello all,

I am attempting to utilize win32_pingstatus. I have used scriptomatic to
exposed the properties of win32_pingstatus but I am running into errors with
following portions of the code:
strRouteRecord = Join(objItem.RouteRecord, ",")
strRouteRecordResolved = Join(objItem.RouteRecordResolved, ",")
strTimeStampRecord = Join(objItem.TimeStampRecord, ",")
strTimeStampRecordAddress = Join(objItem.TimeStampRecordAddress, ",")
strTimeStampRecordAddressResolved =
Join(objItem.TimeStampRecordAddressResolved, ",")

These appear to be arrays which are null and errors are returned. I am able
to run the script if I create If statements to bypass the lines if they are
null but I would like find out if the problem lies with the syntax of the
joins or maybe a problem with these properties in Win32_pingstatus: maybe
they are not fully functional.

Any ideas would be appreciated. Thx in advance.


Here is the full code generated by scriptomatic:

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

arrComputers = Array("PDDCL11041")
For Each strComputer In arrComputers
WScript.Echo
WScript.Echo "=========================================="
WScript.Echo "Computer: " & strComputer
WScript.Echo "=========================================="

Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PingStatus
where Address ='computername'", "WQL", _
wbemFlagReturnImmediately +
wbemFlagForwardOnly)

For Each objItem In colItems
WScript.Echo "Address: " & objItem.Address
WScript.Echo "BufferSize: " & objItem.BufferSize
WScript.Echo "NoFragmentation: " & objItem.NoFragmentation
WScript.Echo "PrimaryAddressResolutionStatus: " &
objItem.PrimaryAddressResolutionStatus
WScript.Echo "ProtocolAddress: " & objItem.ProtocolAddress
WScript.Echo "ProtocolAddressResolved: " &
objItem.ProtocolAddressResolved
WScript.Echo "RecordRoute: " & objItem.RecordRoute
WScript.Echo "ReplyInconsistency: " & objItem.ReplyInconsistency
WScript.Echo "ReplySize: " & objItem.ReplySize
WScript.Echo "ResolveAddressNames: " & objItem.ResolveAddressNames
WScript.Echo "ResponseTime: " & objItem.ResponseTime
WScript.Echo "ResponseTimeToLive: " & objItem.ResponseTimeToLive
strRouteRecord = Join(objItem.RouteRecord, ",")
WScript.Echo "RouteRecord: " & strRouteRecord
strRouteRecordResolved = Join(objItem.RouteRecordResolved, ",")
WScript.Echo "RouteRecordResolved: " & strRouteRecordResolved
WScript.Echo "SourceRoute: " & objItem.SourceRoute
WScript.Echo "SourceRouteType: " & objItem.SourceRouteType
WScript.Echo "StatusCode: " & objItem.StatusCode
WScript.Echo "Timeout: " & objItem.Timeout
strTimeStampRecord = Join(objItem.TimeStampRecord, ",")
WScript.Echo "TimeStampRecord: " & strTimeStampRecord
strTimeStampRecordAddress = Join(objItem.TimeStampRecordAddress, ",")
WScript.Echo "TimeStampRecordAddress: " & strTimeStampRecordAddress
strTimeStampRecordAddressResolved =
Join(objItem.TimeStampRecordAddressResolved, ",")
WScript.Echo "TimeStampRecordAddressResolved: " &
strTimeStampRecordAddressResolved
WScript.Echo "TimestampRoute: " & objItem.TimestampRoute
WScript.Echo "TimeToLive: " & objItem.TimeToLive
WScript.Echo "TypeofService: " & objItem.TypeofService
WScript.Echo
Next
Next
 
S

Scott McNairy \(MVP\)

Try adding these two clauses to your WQL query and see if that helps.

SELECT * FROM Win32_PingStatus
where Address ='computername' AND
resolveAddressNames = true AND
statusCode = 0
 
S

ScottMcNay

I know that this is a late reply, but you should note that
win32_PingStatus is different from all of the other functions, in that
you must run it on your OWN computer; this is because you want YOUR
computer to do the pinging. Otherwise, you are sending the request to
the remote computer, and it is pinging nothing, which won't give you
the quick and correct results that you're expecting. The Scriptomatic
code is the way that it appears because it is created from a template.

Change your code as sown below. You may want to also apply the changes
suggested by Scott McNairy, which will force the code to return results
only if the ping is successful, and to force the system to try to
resolve IPs to addresses (in some cases, you get this info anyway).

Also, as you may be able to guess, you can have a second computer ping
a third one, if you fiddle with the code a bit.

Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PingStatus
where Address ='" & strComputer & "'", "WQL", _
wbemFlagReturnImmediately +
wbemFlagForwardOnly)
 

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