Here is a really simple solution for Vista and Windows 7 that provides the timeout feature, but does not give 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 is a more complex solution for Vista and Windows 7 that provides a visual countdown, but it clears the console window each second. Also the timing 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 then I think you will either need to download a non-native command line tool that asks for input with a timeout feature, or else switch to VBScript or JScript.
EDIT
Both scripts above can be adapted to run on XP by using the CHOICE.EXE download from the Microsoft FTP site that James K provided in his answer.
That version of CHOICE has 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 - Here is a crude VBS solution that is compatible with XP
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 work, and I don't really know much about that technology.