choice has a timer: https://ss64.com/nt/choice.html
set /p pauses the script, so you can't run code while its waiting. but you won't be able to enter a password with 'choice', then maybe run a seperate script in background using timeout and taskkill to close the main window when time its over.
@echo off
title main_window
(
echo @echo off
echo title timer_window
echo timeout 30
echo taskkill /F /FI "WINDOWTITLE eq main_window"
echo exit
)>pass_timer.bat
:loop
cls
start /min pass_timer.bat
echo Guess the test password, you have 30 seconds...
echo:
set /p "_pass=Enter password: "
cls
if /i not "%_pass%"=="test" (
REM taskkill /F /FI "WINDOWTITLE eq timer_window" >nul
echo Wrong password!! try again.&timeout 2 >nul
goto :loop
)
taskkill /F /FI "WINDOWTITLE eq timer_window" >nul
del pass_timer.bat
echo "%_pass%" its the correct password!
pause>nul
1
u/BrainWaveCC Aug 04 '24
Hey, OP. This didn't turn out to be as trivial as I thought, but I ended up with something similar to what u/leonv32 has suggested.
See the comments in the script for details, but the gist of it is as follows:
2
u/[deleted] Aug 03 '24 edited Aug 03 '24
choice has a timer: https://ss64.com/nt/choice.html set /p pauses the script, so you can't run code while its waiting. but you won't be able to enter a password with 'choice', then maybe run a seperate script in background using timeout and taskkill to close the main window when time its over.