怎样寻求批处理文件,用户输入一个超时 [英] How to ask for batch file user input with a timeout

查看:148
本文介绍了怎样寻求批处理文件,用户输入一个超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想一个计时器添加到我的一个,如果一个集指挥下作了发言,但我不知道该命令会是什么。该脚本将启动,并等待30分钟吧重启电脑之前或等待用户输入到输入它在那个时间或取消。所以,我有我的两个,如果对于现在重启和取消设置,但语句现在我需要一个if语句将它从三分钟的时间,降低IT执行我的命令重启之前。此外,如果有人知道如何在显示有多少时间是留给这将是一个加号添加视觉计时器。谢谢你们!!!

  @回响:开始集/ p =答案PC将重新启动在30分钟内,$ P $干燥综合征ñ立即重新开始或c取消如果答案%%==N(GOTO标签1)
如果答案%%==C(GOTO Label2的)
如果TIMER GOES HERE==(GOTO标签1):卷标关机-r -t 60 -f:Label2的出口


解决方案

类似的一个休眠。

 关闭@echo
SETLOCAL enableDelayedExpansion
对/ L %% N的(600 -1 1)做(
  集/ A分= %% N / 60秒= %% n和60 %%,正= 1
  如果!秒! LSS 10集秒!= 0秒!
  CLS
  选择/ C:CN1 / N / M冬眠分钟:!!!!秒 - preSS N至现在冬眠,或C取消。/ T:1 / D:1
  如果没有ERRORLEVEL 3转到:突破

CLS
在0:00回声HIBERNATE - preSS N至现在冬眠,或C取消。
:打破
如果错误级别2(%WINDIR%\\ SYSTEM32 \\ RUNDLL32.EXE powrprof.dll,SetSuspendState休眠)其他回声取消休眠

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

解决方案

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%\System32\rundll32.exe powrprof.dll,SetSuspendState Hibernate) else echo Hibernate Canceled

这篇关于怎样寻求批处理文件,用户输入一个超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆