向用户提供取消选项后自动关机

向用户提供取消选项后自动关机

我想在某些计算机上设置一个脚本或工具,用于在特定时间自动关机,比如深夜,当用户下班后(忘记关机)时。如果某些进程没有响应,它还应该强制关机。但是,如果用户恰好在计算机前使用它,我希望能够显示一个“取消”按钮,比如说 30 秒,以便用户可以取消关机,就像 uTorrent 的可爱方式一样。

我检查了 Daxtar Shutdown(一个不错的工具,但没有调度功能,也没有批处理文件构造功能)和 Simple Shutdown Scheduler(一个不错的工具,但没有取消选项)。我也查看了本论坛中标记为关机的热门问题。我也尝试过在 Windows 批处理文件中使用关机脚本,但无法找到满足关键“用户满意度”要求的方法,即“能够在 N 秒内取消它的选项”。我没有“远程”要求。最好能够在 Windows XP-SP3 和 Windows 7 中使用它。

什么脚本、批处理文件或工具或它们的组合可以实现这一点?

答案1

这是一个镜头,我没有时间用其他方法构建一个来实现这一点,但我想这应该足够了……

笔记这里的数字for /l %%N in (30是需要等待的秒数,所以是3030 秒。

@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

来源

答案2

我想你会发现线有帮助。请仔细阅读,看看是否有帮助。

链接线

用法: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.

谢谢。如果有任何事请告诉我。

相关内容