我知道它可以批量超时30等,但如何做显示倒计时
我在这里看到:
http://www.trytoprogram.com/batch-file/shutdown-commands/
BOTTOM Page“批处理文件程序,用于关闭、重新启动、休眠和注销计算机”
/t 0不好,我做了/t 30,它没有显示倒计时
是否知道如何显示倒计时,如: timeout 30、29、28、27等
发布于 2021-02-27 21:06:24
计时器可以通过使用
循环的秒数,以及一个
循环执行
命令与
使用
不执行任何操作的默认值。
其他选项可以内置于
允许取消关机、重置倒计时或立即关机的循环:
@Echo off
:Reset
For /L %%i in (30 -1 1)Do (
Cls
Echo Shutting down in : %%i Seconds [C]ancel [S]hutdown Now [R]eset Timer
For /F "Delims=" %%G in ('Choice /T 1 /N /C:CSRW /D W')Do (
If %%G==R Goto :Reset
If %%G==C Goto :Eof
If %%G==S Shutdown /SG /T 0
)
)
Shutdown /SG /T 1编辑:
修改上述以用作从菜单调用的函数的示例。
@Echo off
:Menu
Echo [E]xit [L]ogoff [R]estart [S]hutdown
For /F "Delims=" %%G in ('Choice /N /C:SRLE')Do (
If %%G==S Call :Timer "Shutdown /SG /T 1" "Shutting Down"
If %%G==R Call :Timer "Shutdown /R /T 1" "Restarting"
If %%G==L Call :Timer "Shutdown /L" "Logging Off"
If %%G==E Exit /B
)
:# On Cancel Command Selection:
Goto :Menu
:# Function With timer
:Timer [Command] [Prompt]
For /L %%i in (30 -1 1)Do (
Cls
Echo %~2 in : %%i Seconds [C]ancel [R]estart Timer [N]o wait
For /F "Delims=" %%G in ('Choice /T 1 /N /C:CRNW /D W')Do (
If %%G==R Goto :Timer
If %%G==C Goto :Eof
If %%G==N %~1
)
)
%~1发布于 2021-02-27 23:43:28
PsShutdown
你可以用Mark Rusinovich的
psshutdown
它做的就是你想要的:
在指定的时间后启动关机
显示倒计时
允许用户使用取消按钮取消
它是免费使用的。
命令行:
关闭计算机(ACPI电源关闭)
如有必要,强制终止程序
在关机前引入30秒的延迟
允许用户使用取消按钮取消关机

(截图来自
superuser.com
)
选择
另一种选择是调用
多次:
@echo off
set /a "t=30"
:loop
set /a "t-=1"
if "%t%" == "0" goto timedout
cls
choice /T 1 /C sc /N /D s /M "Shutdown in %t% seconds, press c to cancel: "
if not "%errorlevel%" == "1" goto cancelled
goto loop
:cancelled
echo You cancelled shutdown
pause
goto :eof
:timedout
echo Shutting down
shutdown /s /f /t 1
pause
goto :eof设置变量
至30
减法1来自
在以下情况下启动关机
达到零
从屏幕上清除上一个文本
是
它知道它是否被取消,但没有打印时间
-1秒超时(更新消息)
-选项1是s,选项2是c
-不显示
最后
-1秒超时的默认选项为
-显示变量当前值的消息
请注意
可能与
没有时间,所以我把
以防万一。
关闭/a
在倒计时之前实际启动关机可能是有利的,但允许用户中止它:
按照上一节所述进行倒计时(“选择”)。
- You could get away with just plain `timeout` command with a few more seconds in hopes that the batch script is aborted by shutdown before the time runs out but it would be very confusing and unreliable, so this is not recommended在开始倒计时之前(
)开始关机,如下所示:
如果超时,则不执行任何操作(删除
之后
)
如果用户取消(紧接在
),则使用以下命令中止它:
https://stackoverflow.com/questions/66398290
复制相似问题