0

Hey is it possible to make a program in batch that waits for the user 10seconds to type anything if he doesn't type anything the program exits? If yes how?

jakic
  • 13
  • 6

2 Answers2

1

Try this:

choice /c [your key(s)][any different key] /n /d [2nd key] /t 10>nul
if %errorlevel% equ 1 (do stuff here)
if %errorlevel% equ 2 exit /b

Try using choice /? for more help.

1

Give it a shot

@echo off

choice /t 10 /c ynr /cs /d r /m "Do you want it (Y/N)?"
if errorlevel 3 exit
if errorlevel 2 goto :no
if errorlevel 1 goto :yes

:yes
@echo You typed yes 
GOTO :continue

:no
@echo You typed no
GOTO :continue

:continue
@echo And on we go

pause
Rishav
  • 3,515
  • 29
  • 48