Solved

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

Posted on 2010-11-14
1
775 Views
Last Modified: 2012-05-10
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

0
Comment
Question by:thydzik
1 Comment
 
LVL 11

Accepted Solution

by:
thydzik earned 0 total points
ID: 34130753
apologies experts, I have found a solution


function ping2(Target)
	Set WshShell = CreateObject("WScript.Shell")
	ping2 = Not CBool(WshShell.run("ping -n 1 " & Target,0,True))
End Function

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Unlike scripting languages such as C# where a semi-colon is used to indicate the end of a command, Microsoft's VBScript language relies on line breaks to determine when a command begins and ends. As you can imagine, this quickly results in messy cod…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now