Solved

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

Posted on 2010-11-14
1
770 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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

23 Experts available now in Live!

Get 1:1 Help Now