In a cmd window, I want to prompt the user for a set of choices (denoted by letters), one being the default. The user can key in a letter or hit Enter, in which case the default choice will be selected.

I also want to specify a timeout, so the default choice is auto-selected after a given number of seconds of inactivity.

The built-in choice command comes close:

> choice /C YN /T 5 /D Y /M "The message"

This takes only valid choices ( /C YN) and auto-defaults to 'Y' (/D Y) after 5 seconds (/T 5)
... but it strangely does not allow hitting Enter for the default choice.

The other, more verbose option I found permits hitting 'Enter' for the default choice:

set sel=Y

REM Hitting Enter does not modify 'sel'
set /p sel=The message, [Y/N]?

if %sel% == Y goto Yes
if %sel% == N goto No

echo Invalid choice '%sel%', try again.
goto ch

...but I don't know how to make this one auto-select the default after a while.


I don't think there's an option, unless you find some 3rd CLI app that can do it.

How about VBS? it'll be way easier to do that...

  • I'm not opposed to throwing a vbs script in the %PATH% and using it like a built-in command. But I don't know vbs. – Cristi Diaconescu Mar 22 '14 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.