2

I would like to setup a script or a tool on some computers for automatic shutdown, at a given time, say late in the night, when users have left for the day (forgetting to shutdown the computer). It should also force a shutdown if some processes don't respond. However, if a user happens to be at the computer using it, I want to be able to show a Cancel button, for say, 30 seconds, so that the user can cancel the shutdown, like the cute way in which uTorrent does.

I have checked Daxtar Shutdown (a good tool but without scheduling, nor a batch file construct facility) and Simple Shutdown Scheduler ( a good one, but no cancel option ). I have also looked at the top questions tagged with shutdown in this forum. I have also tried using the shutdown script inside a Windows batch file, but not able to find a way to accomplish a key 'user delight' requirement, that is the 'option to be able to cancel it in N seconds'. I have no 'remote' requirement. Preferably, I want to be able to use it in Windows XP-SP3 and Windows 7.

What script, batch file or tool or a combo of these can accomplish this ?

2 Answers 2

1

Give this one a shot, I didn't have time to build one to do this another way but this should suffice I suppose . . .

Note that in the for /l %%N in (30the number here is the amount of seconds to wait so it's 30 for 30 seconds.

@echo off
setlocal enableDelayedExpansion
for /l %%N in (30 -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 "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 RESTART in 0:00 - Press N to Restart Now, or C to Cancel.
:break
if errorlevel 2 (shutdown /r /t 10) else echo restart Canceled

source

1
  • Super! It works like a charm on Windows 7. While I haven't had the chance to try on Windows XP yet, (I read choice.exe doesn't work on XP ?), it's good still.
    – Whirl Mind
    Aug 2, 2016 at 14:28
2

I think you will find this thread helpful. Please go through it and see if it any help.

Link of the thread.

Usage: shutdown [/i | /l | /s | /r | /g | /a | /p | /h | /e] [/f] [/m \computer][/t xxx][/d [p|u:]xx:yy [/c "comment"]]

...

/t xxx     Set the time-out period before shutdown to xxx seconds.
           The valid range is 0-315360000 (10 years), with a default of 30.
           If the timeout period is greater than 0, the /f parameter is
           implied.
/c "comment" Comment on the reason for the restart or shutdown.
           Maximum of 512 characters allowed.
/f         Force running applications to close without forewarning users.
           The /f parameter is implied when a value greater than 0 is
           specified for the /t parameter.

Thank you. Let me know if anything.

1
  • The page points to a /t option that provides for a timeout, within which the shutdown can be cancelled. Good thing, thanks. I am looking for a little more, a way to show a Cancel button so that user can invoke the option provided by /t.
    – Whirl Mind
    Aug 2, 2016 at 11:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.