What Is

Choice.exe: What Is It & How to Use It

This comprehensive guide will help you know how to effectively use the choice.exe command line tool


The Windows operating system comes with different command line tools, and it is quite necessary to understand how these tools work. In previous guides, we discussed some tools like bash.exe and bcdboot.exe. In this article, we will focus on another critical command line tool known as choice.exe.

We will help you discover all there is to know about this file and how to use it effectively.

What is the choice command in cmd?

The CMD’s choice function grants users within batch files the ability to prompt for user input by providing a remarkable command line tool. This crucial component of the Windows system is located in the C:\Windows\System32 folder.

What is an example of a choice command?

Follow the syntax below to run a choice command in the command prompt.
choice [/c [<choice1><choice2><…>]] [/n] [/cs] [/t <timeout> /d <choice>] [/m <text>]

/c [<choice1><choice2><…>] outlines the list of choices to be made.

The /n switch helps hide the number of choices in the prompt.

The /cs switch makes the choices case-sensitive.

The /t <timeout> switch gives the number of seconds to pause before automatically choosing the default option.

The /d <choice> switch determines the default choice to select after waiting the number of seconds outlined by /t <timeout>.

The /m <text> switch sets a message to show before the list of options.

How to use choice and set in a batch file?

Use Choice in a batch file

@echo off rem
This batch file prompts the user to choose Y or N.
choice /c YN /M "Do you want to continue?"
if %errorlevel% == 1 (
rem The user pressed Y. echo Continuing...
else (
rem The user pressed N. echo Exiting...

This batch file will prompt the user to choose Y or N. If the user presses Y, the batch file will continue. If the user presses N, the batch file will exit.

Use set in a batch file

@ECHO off
ECHO 1. Print Hello
ECHO 2. Print Bye
ECHO 3. Print Test
set choice=
set /p choice=Type the number to print text.
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='1' goto hello
if '%choice%'=='2' goto bye
if '%choice%'=='3' goto test
ECHO "%choice%" is not valid, try again
goto start
goto end
goto end
goto end

For the command above, if the values 1, 2, or 3 be inputted, the program will redirect its execution flow to the designated label, where it will promptly execute an echo command. Subsequently, it will proceed to the conclusion of the batch file.

This brings us to the end of this article. We hope we have been able to help you understand the choice.exe command line tool and how to make use of it effectively.

If you have further questions, do not hesitate to contact us via the comment section below.

Leave a Response

David Ogbor
David is a tech guru with extensive knowledge in technical articles. He is passionate about writing and presents technical articles in an easy-to-understand format for easy comprehension. He aims to present easy solutions for day-to-day problems encountered while using PC. In his spare time, he likes traveling, playing sports, and singing.