| 
                                   
Answer»  Hi,
  I am in the process of creating a batch file that will restart a remote computer then log me back in once the computer has finished restarting.  I have everything working except error handling.  All I need is to check to see if my shutdown was successful or failed.
  Here is the part of my code where I need help:
  
Code: [Select]echo off set /p Computer=Restart which computer?  shutdown -r -m %Computer% -f -t 0
  I need to detect if the last line worked or not.  Any help is greatly appreciated.
  Thanks,
  pjpassa I have had to remotely restart systems before and what i do is open a dos shell window and a persistent ping to the IP of the unit that is going to be rebooted. I then can watch as the instructions I passed through another command shell rebooted the computer and it came back online. The systems that were rebooted also had RDP enabled so I could remote into them once they were rebooted to check on services etc.
  In batch I believe you can have a loop that pings the IP until the connection comes back and then it steps to the next process in which it is logging you back on, but SOMEONE else with more batch knowledge would have to show you how to code this up if your looking for the code and not just how to go about doing this.
  I use to use AlertPingPro and it allowed me to add IF conditions, so if the connection was live run a C++ program I wrote and do one thing, or if the connection was down execute another C++ EXE that i created to notify me that the connection was down in which i made a system that would call me when equipment failed as well as I had prerecorded voice messages that would play based on the error condition so that I knew exactly what the PROBLEM was in my voice telling myself over the phone.I was provided a solution on another forum:  http://stackoverflow.com/questions/17195895/checking-to-see-if-cmd-shutdown-command-restarted-remote-computer-on-windows-7
Code: [Select]echo off set DateTime=%Date% %Time% set Comment=Comment: %DateTime% set /p Computer=Restart which computer?  REM Check to see if TARGETED computer is currently online ping -n 1 -w 500 %Computer% | find "TTL" if errorlevel 1 GOTO Error1 cls shutdown -r -m %Computer% -f -t 0 -c "%DateTime% REM Checking to make sure shut down was successful timeout /t 2 /nobreak wevtutil qe system /q:*[System[EventID=1074]] /c:1 /f:text /rd:true /r:%Computer% | find "%Comment%" if errorlevel 1 GOTO Error2 Cool, and thanks for SHARING the end result that worked. I copy/pasted it here from the other site. 
                                 |