*Do not attempt to use this command in your script*
Published on July 8, 2008 By milksama In DesktopX

There is a known issue at the moment with the DesktopX System.Ping() command. Do not attempt to use this as it will crash DesktopX.

I am providing some code that can be used within your script as a workaround. If you prefer to download this, the article link will bring you to an object I have just uploaded. Note that WMI will need to be available on the system on which this is run.

Feel free to copy the following code into your script and use freely. The syntax is completely identical to the System.Ping command, minus the call to the System namespace. Invoke this like so:

MsgBox "Ping response: " & Ping("www.stardock.com")

The WMI Ping function:

Code: vbscript
  1.  Function Ping(strIP)
  2.  Dim objWMI
  3.  On Error Resume Next
  4.  Set objWMI = GetObject("winmgmts:\\.\root\cimv2")
  5.  If objWMI Is nothing Then
  6.   Ping = "Error: WMI Unavailable"  
  7.   Exit Function
  8.  End If
  9.  Dim objPingStatus
  10.  For Each objPingStatus In objWMI.ExecQuery("Select * From Win32_PingStatus Where Address = '" & strIP & "'")
  11.   If IsNull(objPingStatus.StatusCode) Or objPingStatus.Statuscode<>0 Then
  12.      Ping = "Error in Ping query"
  13.     Else
  14.       Ping = objPingStatus.ResponseTime
  15.    End If
  16.   Next
  17. End Function

Thank you RomanDA for the heads up!


Comments
on Jul 08, 2008
Nice code!

May tell you that I don't use the System.InternetConnection. At least on my Vista computer... Here is a code I made for this:

Dim url

url = "www.google.com"

Function IsConnected(url) '<== Using WMI to check the state of internet connection
On Error Resume Next
Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}")
If IsObject(objWMI) Then
Set objPNG = objWMI.ExecQuery("Select ReplySize from Win32_PingStatus Where Address = '"& url &"'","WQL",48)
For Each item In objPNG
If Not IsNull(item.ReplySize) Then IsConnected = True Else IsConnected = False
Next
Set objPNG = nothing
End IF
Set objWMI = nothing
End Function

  
on Jul 08, 2008

Vad_M: Great idea! Thank you for sharing this code with us.

One of the greatest things about DesktopX is its flexibility in being able to perform the same function in multiple different ways.


Mike

on Jul 08, 2008
One of the greatest things about DesktopX is its flexibility in being able to perform the same function in multiple different ways.

Agree.

More than! There are a lot of other very powerfull things included into DesktopX. I even can't imagine what the widget/gadget I wouldn't not make with it!

At the same time I can't understand why Stardock do nothing to develop and popularize this unsurpassed tool... As well why they do nothing to include a possibility of using some other programming languages like Visual Basic or C+. It would be really great!

May be you know any answers for these questions?
on Jul 08, 2008
Thank Mike for posting this one. I am glad its not just me.. LOL

Vad, very cool code. Will have to see how i can implement that.
on Jul 08, 2008
Vad, very cool code. Will have to see how i can implement that.




No comment.