Found WMI Snippets #1 - WIN32_PingStatus
This is a more-or-less complete implementation of the WMI class
WIN32_PingStatus in VFP.
This class has some more platform restrictions as well as not being available in Windows 2000 or 95 or 98:
Starting with Windows Vista, Win32_PingStatus can return data for computers that have both IPv4 addresses and IPv6 addresses.Windows Server 2003 and Windows XP Win32_PingStatus only returns data for computers running IPv4.
It's useful to be able to ping as part of a multi-computer scripting operation as it lets you know if it's worth trying the much more expensive operation of actually trying to connect to the WMI service: if you can't ping, you won't be able to connect to the WMI service, and you find out a lot faster.
Also, and potentially more useful, the StatusCode property could help diagnose connection problems in other scenarios, notably applications and error logging - i.e. 'why are database connections failing - what happens if we ping the database server?" It's a bit easier than parsing the output of Microsoft's ping command, for anything other than the basic outcome at least.
It's been sitting in my draft folder for three or four years so you'll have to excuse any
code-rot.
clear
oWMI = getobject("winmgmts:")
* Specify address or computer name or URL
* cAddress = "192.168.1.125"
cAddress = "apple.com" && Works 21 June 2009 - resolves to 17.112.152.57
* cAddress = "computer_name
if os() < "Windows 5.01"
messagebox("This will only work in Windows XP and later")
return
endif
oPings = oWMI.ExecQuery([Select * from WIN32_Pingstatus where address='] + cAddress + ['])
for each oPing in oPings
* This class does not actually support enumeration,
* there is only one ping object returned and this is how to access it.
? "Status code: ", GetStatusCode(oPing.statuscode)
?
? "Address: ", oPing.Address
? "Buffer size", oPing.BufferSize
? "No Fragmentation", oPing.NoFragmentation
? "PrimaryAddressResolutionStatus", oPing.PrimaryAddressResolutionStatus
? "ProtocolAddress", oPing.ProtocolAddress
? "ProtocolAddressResolved", oPing.ProtocolAddressResolved
? "RecordRoute", oPing.RecordRoute
? "ReplyInconsistency", oPing.ReplyInconsistency
? "ReplySize", oPing.ReplySize
? "ResolveAddressNames", oPing.ResolveAddressNames
? "ResponseTime", oPing.ResponseTime
? "ResponseTimeToLive", oPing.ResponseTimeToLive
? "SourceRoute", oPing.SourceRoute
? "SourceRouteType", GetSourceRouteType(oPing.SourceRouteType)
? "Timeout", oPing.timeout
? "TimestampRoute", oPing.TimestampRoute
? "TimeToLive", oPing.TimeToLive
? "TypeofService", GetTypeOfService(oPing.TypeofService)
if not isnull(oPing.RouteRecord)
for each oItem in oPing.RouteRecord
? oItem
next
endif
if not isnull(oPing.RouteRecordResolved)
for each oItem in oPing.RouteRecordResolved
? oItem
next
endif
if not isnull(oPing.RouteRecordResolved)
for each oItem in oPing.TimeStampRecord
? oItem
next
endif
if not isnull(oPing.TimeStampRecordAddress)
for each oItem in oPing.TimeStampRecordAddress
? oItem
next
endif
if not isnull(oPing.TimeStampRecordAddressResolved)
for each oItem in oPing.TimeStampRecordAddressResolved
? oItem
next
endif
next
procedure GetSourceRouteType
lparameters nSourceRouteType
local cType
do case
case nSourceRouteType = 1
cType = "Loose Source Routing"
case nSourceRouteType = 2
cType = "Strict Source Routing"
otherwise
* Default - 0 - or any other value.
cType = "None"
endcase
return cType
endproc
procedure GetTypeOfService
lparameters nServiceType
local cType as string
do case
case nServiceType = 2
cType = "Minimize Monetary Cost"
case nServiceType = 4
cType = "Maximize Reliability"
case nServiceType = 8
cType = "Maximize Throughput"
case nServiceType = 16
cType = "Minimize Delay"
otherwise
* Default - 0 - or any other value.
cType = "Normal"
endcase
return cType
endproc
procedure GetStatusCode (cCode as string) as string
local cStatus
do case
case cCode = 0
cStatus = "Success"
case cCode = 11001
cStatus = "Buffer Too Small"
case cCode = 11002
cStatus = "Destination Net Unreachable"
case cCode = 11003
cStatus = "Destination Host Unreachable"
case cCode = 11004
cStatus = "Destination Protocol Unreachable"
case cCode = 11005
cStatus = "Destination Port Unreachable"
case cCode = 11006
cStatus = "No Resources"
case cCode = 11007
cStatus = "Bad Option"
case cCode = 11008
cStatus = "Hardware Error"
case cCode = 11009
cStatus = "Packet Too Big"
case cCode = 11010
cStatus = "Request Timed Out"
case cCode = 11011
cStatus = "Bad Request"
case cCode = 11012
cStatus = "Bad Route"
case cCode = 11013
cStatus = "TimeToLive Expired Transit"
case cCode = 11014
cStatus = "TimeToLive Expired Reassembly"
case cCode = 11015
cStatus = "Parameter Problem"
case cCode = 11016
cStatus = "Source Quench"
case cCode = 11017
cStatus = "Option Too Big"
case cCode = 11018
cStatus = "Bad Destination"
case cCode = 11032
cStatus = "Negotiating IPSEC"
case cCode = 11050
cStatus = "General Failure"
otherwise
cStatus = "Unknown"
endcase
return cStatus
endproc