1.

Solve : Checking to see if shutdown command restarted remote computer?

Answer» <html><body><p>Hi,<br/><br/>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.<br/><br/>Here is the part of my code where I need help:<br/><br/> Code: <a>[Select]</a>echo off<br/>set /p Computer=Restart which computer? <br/>shutdown -r -m %Computer% -f -t 0<br/><br/>I need to detect if the last line worked or not.  Any help is greatly appreciated.<br/><br/>Thanks,<br/><br/>pjpassa<br/>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.<br/><br/>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 <a href="https://interviewquestions.tuteehub.com/tag/someone-25657" style="font-weight:bold;" target="_blank" title="Click to know more about SOMEONE">SOMEONE</a> 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.<br/><br/>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++ <a href="https://interviewquestions.tuteehub.com/tag/exe-447113" style="font-weight:bold;" target="_blank" title="Click to know more about EXE">EXE</a> 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 <a href="https://interviewquestions.tuteehub.com/tag/problem-25530" style="font-weight:bold;" target="_blank" title="Click to know more about PROBLEM">PROBLEM</a> was in my voice telling myself over the phone.I was provided a solution on another forum:  <a href="https://stackoverflow.com/questions/17195895/checking-to-see-if-cmd-shutdown-command-restarted-remote-computer-on-windows-7">http://stackoverflow.com/questions/17195895/checking-to-see-if-cmd-shutdown-command-restarted-remote-computer-on-windows-7</a> Code: <a>[Select]</a>echo off<br/>set DateTime=%Date% %Time%<br/>set Comment=Comment: %DateTime%<br/>set /p Computer=Restart which computer? <br/>REM Check to see if <a href="https://interviewquestions.tuteehub.com/tag/targeted-7292618" style="font-weight:bold;" target="_blank" title="Click to know more about TARGETED">TARGETED</a> computer is currently online<br/>ping -n 1 -w 500 %Computer% | find "TTL"<br/>if errorlevel 1 GOTO Error1<br/>cls<br/>shutdown -r -m %Computer% -f -t 0 -c "%DateTime%<br/>REM Checking to make sure shut down was successful<br/>timeout /t 2 /nobreak<br/>wevtutil qe system /q:*[System[EventID=1074]] /c:1 /f:text /rd:true /r:%Computer% | find "%Comment%"<br/>if errorlevel 1 GOTO Error2<br/>Cool, and thanks for <a href="https://interviewquestions.tuteehub.com/tag/sharing-25803" style="font-weight:bold;" target="_blank" title="Click to know more about SHARING">SHARING</a> the end result that worked. I copy/pasted it here from the other site.</p></body></html>


Discussion

No Comment Found