JSI Tip 9825. Another way to test the availability of a remote computer.

In tip 9436 ยป How can I rapidly determine if a computer is available, we used the the PING (Packet InterNet Groper) command to determine if a remote computer was available on the network.

Using WMI, I have scripted CMPAvail.bat to determine if a remote computer is available on the network.

The syntax for using CMPAvail.bat is:

CMPAvail AddressOrName Status


AddressOrName is the IP Address of the remote computer, OR the name of the remote computer, like JSI007 or JSI007.JSIINC.COM.

Status        is a call directed environment variable that will contain:
              a Y if the remote computer is available.
              a N if the remote computer is NOT available.
NOTE: CMPAvail.bat uses Win32_PingStatus, only available on Windows XP, Windows Server 2003, and later.

CMPAvail.bat contains:

@echo off
if \{%2\}==\{\} @echo Syntax: CMPAvail AddressOrName Status&goto :EOF
if exist "%TEMP%\CMPAvail.vbs" goto avail
@echo Dim WshShell, objArgs >"%TEMP%\CMPAvail.vbs"
@echo Set WshShell = CreateObject("WScript.Shell") >>"%TEMP%\CMPAvail.vbs"
@echo Set objArgs = Wscript.Arguments >>"%TEMP%\CMPAvail.vbs"
@echo strComputer = ".">>"%TEMP%\CMPAvail.vbs"
@echo Set objWMIService = GetObject("winmgmts:" _>>"%TEMP%\CMPAvail.vbs"
@echo.     ^& "\{impersonationLevel=impersonate\}!\\" ^& strComputer ^& "\root\cimv2")>>"%TEMP%\CMPAvail.vbs"
@echo Set computers = objWMIService.ExecQuery _>>"%TEMP%\CMPAvail.vbs"
@echo.    ("Select * from Win32_PingStatus Where Address = '" ^& objArgs(0) ^& "'")>>"%TEMP%\CMPAvail.vbs"
@echo For Each objComputer in computers>>"%TEMP%\CMPAvail.vbs"
@echo.     If objComputer.StatusCode = 0 Then>>"%TEMP%\CMPAvail.vbs"
@echo.         Wscript.Echo "Y">>"%TEMP%\CMPAvail.vbs"
@echo.     Else>>"%TEMP%\CMPAvail.vbs"
@echo.         Wscript.Echo "N">>"%TEMP%\CMPAvail.vbs"
@echo.    End If>>"%TEMP%\CMPAvail.vbs"
@echo Next>>"%TEMP%\CMPAvail.vbs"
for /f "Tokens=*" %%a in ('cscript //nologo "%TEMP%\CMPAvail.vbs" %1') do (
 set %2=%%a

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.