How do you add close to a script after so many seconds if an option is not chose.
Example
Option 1 BLah Blah
Option 2 Blaaah Blahhhh
If one of the options is not chose after 5 seconds close the batch.
How to do this anybody?
Code: Select all
@ECHO OFF
CHOICE /C YN /N /T 7 /D N /M "[Y]es or [N]o? (Defaults to "No" in 7 seconds.)"
IF %ERRORLEVEL%==1 (
echo YES!
goto :break
)
IF %ERRORLEVEL%==2 (
echo NO!
goto :break
)
:break
This is pretty good too, it will show you the actual countdown:
Code: Select all
@ECHO OFF
setlocal enableDelayedExpansion
FOR /l %%N in (7 -1 1) do (
set /a "min=%%N/60, sec=%%N%%60, n-=1"
IF !sec! lss 10 set sec=0!sec!
CLS
CHOICE /C:YNX /M "Do you want me to say 'Hello world'? [Y/N] (!min!:!sec!) " /T:1 /D:X /N
IF NOT ERRORLEVEL 3 GOTO :break
)
:break
IF %ERRORLEVEL% == 1 (
echo HELLO WORLD.
)
IF %ERRORLEVEL% == 2 (
echo NO.
)
IF %ERRORLEVEL% == 3 (
echo Nothing was chosen.
)