Shell function

janz

Registered User.
Local time
Today, 08:27
Joined
Jan 25, 2008
Messages
44
Hi there I got again a tricky one who can help?

Any body an idea how I can get the ping time in ms from the ping command?

I tried
a=shell("ping 173.194.65.94",vbMaximizedFocus) (pinging the google site)
Works very good however I need to know the ping time.

So (being older and familiar with DOS) I tried
a=shell("ping 173.194.65.94 >c:\temp.txt",vbMaximizedFocus)
to get the text in a file and then read it from the file.
but no go.
If I try from the command prompt it works perfect the ping is done and the reply text is put in file c:\temp.txt however with the shell command it will not work.

I thought maybe it is because the shell command doesn't stop until finished.
I already had a program that stops until the shell command is executed (working perfect for years) so tried that but that didn't fix it either.

Any body a golden tip?
 
Hi Galaxiom,
Your absolutely correct this is what I need.

The base of your (2 programs) seems to run fine. However I run into problems when I run into the "wscript.Echo" section. I never used this type of programming before. It keeps giving me an error 424 Object required.

Could it be that I'm missing a reference?
Could you please point me in the right direction (again)
 

Attachments

  • ref.gif
    ref.gif
    6.4 KB · Views: 100
The WScript object is from the VB Script. Have a look at the other link in the same post where I showed a VBA version.
 
Hi Galaxiom It's all working now. Really simple if you know how ;-)
I use it as function in a timed program and store the values in a Db.
Thanks for your help.

I will open a new threat "Local area connection" with a follow up question. Please have a look at that if you can find the time.

for all people interested this is my simplified VBA code.


Code:
Public Function pingit(sTratget as string)
‘   sTarget =  name or IP address of remote computer to which connectivity will be tested
‘Pings a line and returns the milli seconds it took or the error code at time out

Dim cPingResults    'collection of instances of Win32_PingStatus class
Dim oPingResult     'single instance of Win32_PingStatus class
Dim strQuery As String
   
	 strQuery = "SELECT * FROM Win32_PingStatus WHERE Address = '" & sTarget & "'"
 	Set cPingResults = GetObject("winmgmts://./root/cimv2").ExecQuery(strQuery)

	For Each oPingResult In cPingResults
    		If oPingResult.StatusCode = 0 Then
			‘responding
       			 pingit = oPingResult.ResponseTime
   		Else
			‘not responding error code
       			 pingit = Val(oPingResult.StatusCode) +900000 ‘put a 9 in front not to lose any zero 
    		End If
	Next

End Function
 
Last edited:

Users who are viewing this thread

Back
Top Bottom