Determine an amount of time to respond to something in Batch

Asked

Viewed 172 times

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 shut down the computer, the user would have 1 minute to respond to something in that batch, if I do nothing, the command cancels.

1 answer

1


Yes, it’s possible to do that.

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 press Enter without typing anything the shutdown command will not be canceled.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.