Command to automatically exit a batch if left inactive?


I was wondering if there was a command to automatically exit a batch file if it is left alone for a certain number of seconds.

I made a little program similar to the one found here. Most of the coding I used is displayed on the page, but it basically asks you what website you want to visit, and selecting one of the options opens a browser window with the desired page. however, after selecting one of the listed sites, the program displays the options to either exit or return to the top. This is where I usually forget about it until I close whatever I was looking at, and the batch is still open in the background.

So is there anyway to set a auto-exit timer without it interrupting the user, and without restricting the ability to go back and select another option?


You can use choice command, instead set /p

Where z is an automatic option, you can use another letter.

/D is the default option if time is passed. /T is the time to wait (this case, 5 seconds).

choice /n /c:zbe /T 5 /D x /M "Make your selection"

Then use it on your code:

choice /n /c:xbe /T 5 /D x  /M "Make your selection"
if errorlevel 1 exit
if errorlevel 2 goto :option_b
if errorlevel 3 goto :option_e

More info type in cmd: choice /?