如何在超时时要求批处理文件用户输入

编程入门 行业动态 更新时间:2024-10-28 02:31:41
本文介绍了如何在超时时要求批处理文件用户输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图在 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:关键词]

本文发布于:2023-03-28 18:16:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/737086.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:批处理文件   用户   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!