JSI Tip 1880. The Resource Kit Choice command.

Choice prompts the user to make a choice in a batch program by displaying a prompt and pausing for the user to choose from among a set of keys. You can use this command only in batch programs.

Syntax: choice \[/c\[:\]choices\] \[/n\] \[/s\] \[/t\[:\]c,nn\] \[text\]


  /c\[:\]choices      specifies allowable keys in the prompt. When displayed, the keys will be separated by commas, will appear in brackets (\[\]), and will be followed by a question mark. If you don't specify the /c switch, Choice uses YN as the default (which displays as \[Y, N\]). The colon (:) is optional.   
  /n      causes Choice not to display the prompt. The text before the prompt is still displayed, however. If you specify the /n switch, the specified keys are still valid.   
  /s      causes Choice to be case-sensitive. If the /s switch is not specified, Choice will accept either uppercase or lowercase for any of the keys that the user specifies.   
  /t\[:\]c,nn      causes Choice to pause for a specified number of seconds before defaulting to a specified key. The values for the /t switch are as follows: c = the character to default to after nn seconds. The character must be in the set of choices specified in the /c switch. nn = the number of seconds to pause. Acceptable values are from 0 to 99. If 0 is specified, there will be no pause before defaulting.   
  text      specifies text you want to be displayed before the prompt. Quotation marks are necessary only if you include a switch character (/) as part of the text before the prompt. If you don't specify text, Choice displays only a prompt.   


When you use the following syntax in a batch file: 

  choice /c:ync

causes the following to display when Choice is started: 


Adding text to the syntax: 

  choice /c:ync Yes, No, or Continue

causes the following to display when Choice is started: 

  Yes, No, or Continue \[Y,N,C\]?

Using the /n switch to leave out the prompt in a batch program: 

  choice /n Yes, No, or Continue?

means the user sees only the text you specified when CHOICE is started: 

  Yes, No, or Continue?

Using the /t Switch

choice /c:ync /t:n,5

means the user sees the following when CHOICE is started:


If the user doesn't press a key within 5 seconds, 
CHOICE selects N and returns an ERRORLEVEL value of 2.
Otherwise, CHOICE returns the value corresponding to the user's choice.

ERRORLEVEL is set to the offset of the key that the user presses in choices.

The first key you assign returns a value of 1, the second a value of 2,
the third a value of 3, and so on. If the user presses a key that is not 
among the keys you assigned, CHOICE sounds a warning beep 
(that is, it sends a BEL, or 07h, character to the console).

If CHOICE detects an error condition, it returns an ERRORLEVEL value of 255.

If the user presses CTRL+BREAK or CTRL+C, CHOICE returns an ERRORLEVEL value of 0.

When you use ERRORLEVEL parameters in a batch program, list them in decreasing order.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.