Here is a very simple solution for Vista and Windows 7 that provides a timeout function but does not provide a visual countdown.
@echo off choice /c:CN /n /m "PC will restart in 30 minutes. Press N to restart Now, or C to Cancel" /t:1800 /d:N if errorlevel 2 (shutdown -r -t 60 -f) else echo Restart Canceled
Here's a more sophisticated solution for Vista and Windows 7 that provides a visual countdown but clears the console window each time. Also the time is probably a bit off.
@echo off setlocal enableDelayedExpansion for /l %%N in (1800 -1 1) do ( set /a "min=%%N/60, sec=%%N%%60, n-=1" if !sec! lss 10 set sec=0!sec! cls choice /c:CN1 /n /m "PC will restart in !min!:!sec! - Press N to restart Now, or C to Cancel. " /t:1 /d:1 if not errorlevel 3 goto :break ) cls echo PC will restart in 0:00 - Press N to restart Now, or C to Cancel. :break if errorlevel 2 (shutdown -r -t 60 -f) else echo Restart Canceled
If you need an XP solution, I think you will need to download a non-native command line tool that asks for input with a timeout function, or switch to VBScript or JScript.
EDIT
Both of the scenarios above can be adapted to run on XP by downloading CHOICE.EXE from the Microsoft FTP site , which James K provided in his answer.
This version of CHOICE has a slightly different syntax.
To adapt my first script, use:
choice /c:CN /n /t:N,1800 "PC will restart in 30 minutes. Press N to restart Now, or C to Cancel"
To adapt my second script, use:
choice /c:CN1 /n /t:1,1 "PC will restart in !min!:!sec! - Press N to restart Now, or C to Cancel. "
EDIT is the coolest XP compatible VBS solution
Set objShell = CreateObject("WScript.Shell") for i = 30 to 1 step -1 if i=1 then unit=" minute" else unit=" minutes" rtn = objShell.Popup ( _ "The machine would like to Restart."&VbCrLf&VbCrLf& _ "Click OK to restart now"&VbCrLf& _ "Click Cancel or the [X] close button to abort the restart"&VbCrLf& _ "Do nothing and the machine will restart in "&i&unit, _ 60, "Restart in "&i&unit, 1+48 _ ) if rtn <> -1 then exit for next if rtn <> 2 then objShell.Run "shutdown -r -f"
I think you can provide a more elegant VBS solution using HTA, but that is a lot more, and I really know little about this technology.