It is sometimes useful to determine if a remote computer is available. When you attempt to connect
to a remote computer, you will experience a timeout if the computer is not available. This timeout
can be 30 seconds. To avoid this, functions have been developed that ping the computer. If the remote
computer responds to the ping, you attempt the connection. Four such functions are documented below.
The one you select will depend on the operating system and version of WSH you want the program to
The first function requires a 32-bit operating system and WSH 5.1, which comes standard with every Windows operating system since Windows 95, if DSClient is installed. This is the function used in the example programs on this web site. It uses the Run method of the wshShell command to execute the ping command. The output is piped to a temporary file. The FileSystemObject is used to open the temporary file as a TextStream object. If the output indicates that the remote computer responded to the ping, the function returns True. This function requires that you setup the temporary file ahead of time and delete it when you are finished. The function is based on a program developed by Alex Angelopoulos and Torgeir Bakken, two Microsoft MVP's (Most Valuable Professionals) and posted in the newsgroups. Parameters allow you to specify the number of pings and the timeout in milliseconds.
Ping1.txt <<-- Click here to view or download the program
The second function requires WSH 5.6, which comes standard on Window XP and above. It can be installed on other operating systems. It uses the Exec method of the wshShell object to execute the ping command. The output is captured by the StdOut method. This function does not require a temporary file. Parameters allow you to specify the number of pings and the timeout in milliseconds.
Ping2.txt <<-- Click here to view or download the program
The third function uses the WMI Win32_PingStatus class, which requires Windows XP or above. This function is based on code in the Microsoft Script Center at the following link:
In addition, on Windows XP and Windows Server 2003 computers the Win32_PingStatus class can only return information on remote computers running IPv4. On Windows Vista and above the Win32_PingStatus class can return information on remote computers that have either IPv4 or IPv6 addresses. An IPv4 address is similar to 192.168.234.122. An IPv6 address is similar to 2010:836B:4179::836B:4179. This function does not allow you to specify the number of pings or the timeout. The default timeout is 1000 milliseconds.
Ping3.txt <<-- Click here to view or download the program
Finally, Tom Lavedas, a regular in the newsgroups, has revised the first ping program above so it no longer requires a temporary file. This is a much cleaner solution. However, it does not work on clients with Windows 95 or Window 98 because the redirection of STDERR is not supported. If you run Ping4.vbs on a Win9x computer, a zero byte file named &1 is created in the current directory and the function always returns True. The program should work if the client operating system is Windows NT or above.
Ping4.txt <<-- Click here to view or download the program
In all four programs linked above, note that the ping can be blocked by a firewall, or you may be asked if the program has your permission to access the Internet. These programs have been modified so they work on the new operating systems, like Windows 7, with IPv6.