Download Article
Download Article
Are you really good at programming Batch Files, but you just don't know how to make those yes or no Choices or Menus that list Choices 1, 2, and 3? Well you've come to the correct place!
Steps
-
Click Start>Run
-
Type "cmd" (no quotations)Advertisement
-
Type "edit"
-
Type the following, careless of bolded/unbolded worlds. After each press enter. Anything in parenthesis do NOT type, these are side-notes that tries to explain the steps.
-
@echo off (This command will 'hide' the command input - optional but recommended)
-
cls (This will clear anything above - optional but recommended if you're wanting to make it look neat)
- start
-
echo.
-
echo Choice 1 ("Choice 1" can be renamed to whatever you want, any of the choices)
-
echo Choice 2
-
echo Choice 3 (Keep doing that until you have all of the choices that you need. )
-
Type "set /p choice=(Insert question or command here, like "Yes or no?" )
-
if not '%choice%'== set choice=%choice: ~0,1%
-
if '%choice%'=='1' goto :choice1
-
if '%choice%'=='2' goto :choice2
-
(Continue doing this pattern until you have enough. Then type:)
-
echo "%choice%" is not a valid option. Please try again.
-
echo.
-
goto start
-
(commands you want to run)
-
(commands)
-
(commands)
-
goto end
-
pause
-
exit
-
29Save this as a .bat file. Double click to test your batch file.
Advertisement
Community Q&A
Search
-
QuestionTrue or false: you can open Notepad using run options?Felix VincentCommunity AnswerTrue, type in notepad or notepad.exe. Also, you can use CMD for that with "start Notepad."
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement
Example
@
ECHO
off cls
:
start
ECHO
. ECHO
1. Print Hello ECHO
2. Print Bye ECHO
3. Print Test set
/p
choice
=
Type the number to print text. rem if not '%choice%'=='' set choice=%choice:~0;1% ( don`t use this command, because it takes only first digit in the case you type more digits. After that for example choice 23455666 is choice 2 and you get "bye"
if
' %choice%
' ==
'' ECHO
"
%choice%
"
is not valid please try again if
' %choice%
' ==
'1' goto
hello
if
' %choice%
' ==
'2' goto
bye
if
' %choice%
' ==
'3' goto
test
ECHO
. goto
start
:
hello
ECHO
HELLO goto
end
:
bye
ECHO
BYE goto
end
:
test
ECHO
TEST goto
end
:
end
pause
exit
Tips
- Type choice /? in the Command Prompt for more info.Thanks
- Type /help in the Command Prompt for more info.Thanks
- Edit command in command prompt does not work in Windows 8. This command is available for windows XP/Vista/Windows 7.Thanks
Submit a Tip
All tip submissions are carefully reviewed before being published
Name
Please provide your name and last initial
Thanks for submitting a tip for review!
Advertisement
Warnings
- Command that are used without knowledge may harm your computer.Thanks
- Do not use commands unless you know what you are doing.Thanks
Advertisement
About This Article
Thanks to all authors for creating a page that has been read 251,085 times.
Advertisement