Avatar of Travis Hydzik
Travis Hydzik
Flag for Australia asked on

VBScript ping function that doesn' use GetObject or show a cmd windows

All,

I have the following requirements;
I require a basic ping function that takes a host/ip string and returns a Boolean true if successfully pinged.

*It cannot use GetObject
*it cannot show a cmd prompt
*It cannot use a temporary file

I have the following code which I like, but for a moment it shows the cmd prompt, it hangs even longer if an invalid host name was entered (but this can be avoided by sticking to ips)

Does anyone have a solution that meets the above requirements?


msgbox ping("localhost")

Function Ping(Target)
Dim results

    'On Error Resume Next

    Set shell = CreateObject("WScript.Shell")
    
    ' Send 1 echo request, waiting 2 seconds for result 
    Set exec = shell.Exec("ping -n 1 -w 1000 " & Target)
    results = exec.StdOut.ReadAll
    
    Ping = InStr(1,results, "reply from",vbtextcompare) > 0
End Function

Open in new window

VB Script

Avatar of undefined
Last Comment
Travis Hydzik

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Travis Hydzik

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes