Determine an amount of time to respond to something in Batch

2

Is it possible to determine an amount of time for the user to answer a question in a batch? If I were to use a batch to turn off the computer, the user would have 1 minute to answer something in that batch, if he did nothing, the command would abort.

    
asked by anonymous 05.12.2017 / 18:02

1 answer

1

Yes, you can do this.

Create a file with the following commands:

@echo off
rem Programado o desligamento em 2 minutos (120 segundos)
shutdown -s -t 120
rem Esperando entrada do usuário, se não digitar nada não cancela o desligamento.
:verifica
echo Digite algo:
set /p "info="
rem Verificar se digitou alguma informação ou apenas deu enter.
IF "%info%"=="" (
    rem Se não digitou nada volta a pedir para digitar algo.
    goto verifica
) else (
    rem Cancela desligamento.
    shutdown -a
    echo Desligamento cancelado!
)
pause > nul
  

If you press Enter without typing anything, the shutdown command will not be canceled.

    
05.12.2017 / 18:24