Solved

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

Posted on 2010-11-14
1
790 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Suggested Courses

628 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