Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Checking to see if shutdown command restarted remote computer  (Read 4506 times)

0 Members and 1 Guest are viewing this topic.

pjpassa

    Topic Starter


    Newbie

    • Experience: Experienced
    • OS: Windows 7
    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

    DaveLembke



      Sage
    • Thanked: 662
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Checking to see if shutdown command restarted remote computer
    « Reply #1 on: June 19, 2013, 01:52:17 PM »
    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.

    pjpassa

      Topic Starter


      Newbie

      • Experience: Experienced
      • OS: Windows 7

      DaveLembke



        Sage
      • Thanked: 662
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: Checking to see if shutdown command restarted remote computer
      « Reply #3 on: June 21, 2013, 01:26:21 PM »
      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.