问题描述
所以我试图在 set 命令下向我的 if 语句之一添加一个计时器,但我不确定该命令是什么.该脚本将启动并等待 30 分钟,然后重新启动 PC 或等待用户在那时输入或取消它.因此,我设置了立即重启"和取消"的两个 if 语句,但现在我需要一个 if 语句,让它从 30 分钟开始倒计时,然后再执行我的重启命令.此外,如果有人知道如何在那里添加一个可视化计时器来显示剩余的时间,那将是一个加号.谢谢各位!!!
So I am trying to add a timer to one of my if statements under a set command but I'm not sure what the command would be. The script will launch and wait thirty minutes before it reboots the PC or wait for a users input to input it at that time or cancel it. So I have my two if statements for the "restart now" and "cancel" set but now I need an if statement to have it count down from thirty minutes before it executes my restart command. Also if anyone knows how to add a visual timer on there showing how much time is left that would be a plus. Thanks guys!!!
@Echo off
:START
set /p answer=PC WILL RESTART IN 30 MINUTES, PRESS N TO RESTART NOW OR C TO CANCEL
if "%answer%"=="n" (GOTO Label1)
if "%answer%"=="c" (GOTO Label2)
if "TIMER GOES HERE" "==" (GOTO Label1)
:Label1
shutdown -r -t 60 -f
:Label2
exit
推荐答案
hibernate 类似.
Similar one for hibernate.
@echo off
setlocal enableDelayedExpansion
for /l %%N in (600 -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 "HIBERNATE in !min!:!sec! - Press N to hibernate Now, or C to Cancel. " /t:1 /d:1
if not errorlevel 3 goto :break
)
cls
echo HIBERNATE in 0:00 - Press N to hibernate Now, or C to Cancel.
:break
if errorlevel 2 (%windir%System32undll32.exe powrprof.dll,SetSuspendState Hibernate) else echo Hibernate Canceled
这篇关于如何在超时时要求批处理文件用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论