We help IT Professionals succeed at work.
Get Started

Batch file - Check if Machine is online first

noodleNT asked
Last Modified: 2012-08-14
I have a list of computers dumpted from AD. I then call that up that file and want to test if the machine is online or not. I was trying to use Net View \\Computer but would get an error 53 if the machine wasn't online. Is there any way I can do a simple test for that?

If error = 53 then Set Online=False

Something like that.

This is my current code:

For /F "delims=" %%i in (%FileInput%) do (
      Echo Computer: %%i
      set /a LineCount=+1
      Echo LineCount: %LineCount%

      ECHO. >>C:\Scripts\xcacls\LOG_MSFIX.txt
      ECHO. >>C:\Scripts\xcacls\LOG_MSFIX.txt
      ECHO ******************************************************** >>C:\Scripts\xcacls\LOG_MSFIX.txt
      ECHO COMPUTER: %%i >>C:\Scripts\xcacls\LOG_MSFIX.txt
      ECHO ******************************************************** >>C:\Scripts\xcacls\LOG_MSFIX.txt

      For /F "Tokens=1" %%a in ('Net view "\\%%i"') do set Online=%%a      
      Echo Online="%online%"

      IF "%Online%" == "error" (
            ECHO %%i did not respond at %Time% >>C:\Scripts\xcacls\LOG_MSFIX.txt
      ) Else (
            ECHO %%i ALIVE! at %Time% >>C:\Scripts\xcacls\LOG_MSFIX.txt
Watch Question
Technology and Business Process Advisor
Most Valuable Expert 2013
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE