System.Ping command broken

*Do not attempt to use this command in your script*

Tuesday, July 8, 2008 by milksama | Discussion: 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!

Vad_M
Reply #1 Tuesday, July 8, 2008 12:19 PM
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

  
milksama
Reply #2 Tuesday, July 8, 2008 2:39 PM

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

Vad_M
Reply #3 Tuesday, July 8, 2008 3:15 PM
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?
RomanDA
Reply #4 Tuesday, July 8, 2008 4:38 PM
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.
ZubaZ
Reply #5 Tuesday, July 8, 2008 4:44 PM
Vad, very cool code. Will have to see how i can implement that.




No comment. 


Please login to comment and/or vote for this skin.

Welcome Guest! Please take the time to register with us.
There are many great features available to you once you register, including:

  • Richer content, access to many features that are disabled for guests like commenting on the forums and downloading skins.
  • Access to a great community, with a massive database of many, many areas of interest.
  • Access to contests & subscription offers like exclusive emails.
  • It's simple, and FREE!



web-wc01