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
  • 23
  • 7
  • 6
    http://stackoverflow.com/questions/17359345/timeout-for-user-decision-in-windows-batch-file – 001 May 13 '16 at 21:09

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.

Matthew Horvath
  • 186
  • 1
  • 12
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,818
  • 1
  • 31
  • 49