Thanks for the great info!
--
Ramesh, Microsoft MVP
Windows XP Shell/User
http://windowsxp.mvps.org
Torgeir Bakken (MVP) said:
Looking for some sort of "is alive" command similiar to ping, but which
would return whether or not
a machine is powered on at the moment. I can ping the machine and output
the results to a file, but
then I have to sort through that file to get the result. Looking for some
command-line app/utility which
will give me an errorlevel I can script against.
Hi
This should work for WinXP:
'--------------------8<----------------------
@echo off
set host=128.33.12.144
ping -n 1 %host% >nul
if %ERRORLEVEL% EQU 0 echo %host% is online
'--------------------8<----------------------
Note that the above will not work very well in all cases when
running the script from a Windows 2000 computer.
Sadly, on Win2k, ping.exe will return errorlevel 0 even if
computer is unavailable (offline/turned off) but defined in
DNS (ping will return "Request timed out.")
From my testing, the only time the function will return a correct
"False" value is where ping returns "Unknown host".
Parsing the output from ping.exe and looking for "TTL=" is the way
I have found that will work in all situations/OS versions/languages.
So this should work fine for both WinXP and Win2k:
'--------------------8<----------------------
set host=128.33.12.144
set connected=N
for /f "Tokens=*" %%c in ('ping -n 1 %host% ^| FIND "TTL="') do (
set connected=Y
)
if "%connected%" EQU "Y" echo %host% is online
'--------------------8<----------------------