Search code examples
cmdshutdowninteractiverestartabort

CMD to have a keystroke stop a script


I need to create a batch script that will run a reboot command but give you the option to stop the script with "the push of any key".
Ultimately I want to add it to my scheduled tasks set at 3:00 am and have it countdown from 30 minutes. I want to give it the thirty minutes in case a user is away from a PC and it initiates while they are still working on it.

shutdown -r -t 1800

press any key to abort (this part I don't know how to do)


Solution

  • Put:

    pause
    shutdown -a 
    

    If user does not (navigate to cmd window and) and press 'a key', timer will elapse and shutdown will start, otherwise it will be aborted