D
Dave Marden
I currently use this routine in vbscript to ping computers and get the
status of ping to determine whether to try to backup a machine, I am trying
to change it to work with vb2003.net I am wondering if anyone has a ping
function they could share with me.
I have done some searching on this but cannot find anything specifically for
vb2003.
Sub PingComputer
If PingStatus(PCName) = "Success" Then
RunBackup
End If
End Sub
Function PingStatus(strWorkStation)
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strWorkStation & "\root\cimv2")
Set colPings = objWMIService.ExecQuery _
("SELECT * FROM Win32_PingStatus WHERE Address = '" & MachineInfo(0) &
"'")
For Each objPing in colPings
Select Case objPing.StatusCode
Case 0 PingStatus = "Success"
Case 11001 PingStatus = "Ping UnSuccessful -- Buffer Too Small"
Case 11002 PingStatus = "Ping UnSuccessful -- Destination Net
Unreachable"
Case 11003 PingStatus = "Ping UnSuccessful -- Destination Host
Unreachable"
Case 11004 PingStatus = "Ping UnSuccessful -- Destination Protocol
Unreachable"
Case 11005 PingStatus = "Ping UnSuccessful -- Destination Port
Unreachable"
Case 11006 PingStatus = "Ping UnSuccessful -- No Resources"
Case 11007 PingStatus = "Ping UnSuccessful -- Bad Option"
Case 11008 PingStatus = "Ping UnSuccessful -- Hardware Error"
Case 11009 PingStatus = "Ping UnSuccessful -- Packet Too Big"
Case 11010 PingStatus = "Ping UnSuccessful -- Request Timed Out"
Case 11011 PingStatus = "Ping UnSuccessful -- Bad Request"
Case 11012 PingStatus = "Ping UnSuccessful -- Bad Route"
Case 11013 PingStatus = "Ping UnSuccessful -- TimeToLive Expired Transit"
Case 11014 PingStatus = "Ping UnSuccessful -- TimeToLive Expired
Reassembly"
Case 11015 PingStatus = "Ping UnSuccessful -- Parameter Problem"
Case 11016 PingStatus = "Ping UnSuccessful -- Source Quench"
Case 11017 PingStatus = "Ping UnSuccessful -- Option Too Big"
Case 11018 PingStatus = "Ping UnSuccessful -- Bad Destination"
Case 11032 PingStatus = "Ping UnSuccessful -- Negotiating IPSEC"
Case 11050 PingStatus = "Ping UnSuccessful -- General Failure"
Case Else PingStatus = "Ping UnSuccessful -- Unable to determine cause of
failure."
End Select
Next
End Function
Thanks In Advance,
Dave Marden
status of ping to determine whether to try to backup a machine, I am trying
to change it to work with vb2003.net I am wondering if anyone has a ping
function they could share with me.
I have done some searching on this but cannot find anything specifically for
vb2003.
Sub PingComputer
If PingStatus(PCName) = "Success" Then
RunBackup
End If
End Sub
Function PingStatus(strWorkStation)
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strWorkStation & "\root\cimv2")
Set colPings = objWMIService.ExecQuery _
("SELECT * FROM Win32_PingStatus WHERE Address = '" & MachineInfo(0) &
"'")
For Each objPing in colPings
Select Case objPing.StatusCode
Case 0 PingStatus = "Success"
Case 11001 PingStatus = "Ping UnSuccessful -- Buffer Too Small"
Case 11002 PingStatus = "Ping UnSuccessful -- Destination Net
Unreachable"
Case 11003 PingStatus = "Ping UnSuccessful -- Destination Host
Unreachable"
Case 11004 PingStatus = "Ping UnSuccessful -- Destination Protocol
Unreachable"
Case 11005 PingStatus = "Ping UnSuccessful -- Destination Port
Unreachable"
Case 11006 PingStatus = "Ping UnSuccessful -- No Resources"
Case 11007 PingStatus = "Ping UnSuccessful -- Bad Option"
Case 11008 PingStatus = "Ping UnSuccessful -- Hardware Error"
Case 11009 PingStatus = "Ping UnSuccessful -- Packet Too Big"
Case 11010 PingStatus = "Ping UnSuccessful -- Request Timed Out"
Case 11011 PingStatus = "Ping UnSuccessful -- Bad Request"
Case 11012 PingStatus = "Ping UnSuccessful -- Bad Route"
Case 11013 PingStatus = "Ping UnSuccessful -- TimeToLive Expired Transit"
Case 11014 PingStatus = "Ping UnSuccessful -- TimeToLive Expired
Reassembly"
Case 11015 PingStatus = "Ping UnSuccessful -- Parameter Problem"
Case 11016 PingStatus = "Ping UnSuccessful -- Source Quench"
Case 11017 PingStatus = "Ping UnSuccessful -- Option Too Big"
Case 11018 PingStatus = "Ping UnSuccessful -- Bad Destination"
Case 11032 PingStatus = "Ping UnSuccessful -- Negotiating IPSEC"
Case 11050 PingStatus = "Ping UnSuccessful -- General Failure"
Case Else PingStatus = "Ping UnSuccessful -- Unable to determine cause of
failure."
End Select
Next
End Function
Thanks In Advance,
Dave Marden