Solved

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Attention Please 10 48
powershell script 9 63
VBA taking too long 5 24
Save and close already open Excel file using VBscript 9 47
Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

809 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