ping in vbscript


I wrote a script to get the output of ping every few minutes.
This is part of my script:

Set objShell = CreateObject("WScript.Shell")
Set objExec = objShell.Exec("ping -n 4 -w 1000 " & serverName)
strPingResults = LCase(objExec.StdOut.ReadAll)

Since ping runs in a window, a window pops up every few minutes when my script is running and I don't want that. I would like to get the output from pinging a server without a window showing up every few minutes. How can I do that? Should I be calling some other ping program?

Thank you
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Check out;en-us;300197 ("HOW TO: Ping an IP Address with Visual Basic by Using ICMP"), maybe you can change that to work with VBS.
I don't know of a way to hide the window using objShell.Exec

If the link above doesn't work out for you then let me know what you would like to with the
"strPingResults" and I will post a script for you
newpersonAuthor Commented:
From strPingResults, I need to get the average response time. For example, if this is the output of ping, I need to get the number 40.

Pinging [] with 32 bytes of data:
Reply from bytes=32 time=40ms TTL=240
Reply from bytes=32 time=40ms TTL=240
Reply from bytes=32 time=40ms TTL=240
Reply from bytes=32 time=40ms TTL=240
Ping statistics for
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 40ms, Maximum =  40ms, Average =  40ms

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.


Here is a sample that will get the response time of a ping
but we have to use a loop to ping 4 times to find the average:

'!!!Begin Copy
Dim strHost, strTarget, colPingResults, objPingResult, strPingRT,i

strHost = "."
strTarget = ""

Do Until i = 4
Set colPingResults = GetObject("winmgmts:{impersonationLevel=impersonate}//" & _
        strHost & "/root/cimv2").ExecQuery("SELECT * FROM Win32_PingStatus " & _
        "WHERE Address = '" + strTarget + "'")

For Each objPingResult In colPingResults
    If objPingResult.StatusCode = 0 Then
       Ping = True
        strPingRT = strPingRT + objPingResult.responsetime
        Ping = False
    End If
i = i + 1
wscript.echo strPingRT / 4

'!!End Copy

the line (line 12)....If objPingResult.StatusCode = 0 Then...
is there incase your script needs to know if there was a response or not.
newpersonAuthor Commented:
But does Win32_PingStatus work on Windows 2000? I am getting an error when I run this script...
Well you are right it doesn't work in W2K...sorry

The best I can come up with is to use cscript.exe to call your existing vbs file.
I have tried this on my W2k machine and it worked

Place these 2 lines in a seperate vbscript and replace c:\ExistingFile.vbs with your existing file
If there is a space in the folder path you will need to use the 8.3 format...e.g Documents and Settings = docume~1

Set wshshell = CreateObject("WScript.Shell") "cmd /c cscript //nologo c:\ExistingFile.vbs",0

Good Luck!


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Glad it worked out for you...thanks for the points
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows 2000

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.