Explore this Article
X
wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, 13 people, some anonymous, worked to edit and improve it over time.
The wikiHow Tech Team also followed the article's instructions and verified that they work.
This article has been viewed 239,622 times.
Learn more...
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
-
1Click Start>Run
-
2Type "cmd" (no quotations)Advertisement
-
3Type "edit"
-
4Type 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.
-
5@echo off (This command will 'hide' the command input - optional but recommended)
-
6cls (This will clear anything above - optional but recommended if you're wanting to make it look neat)
- start
-
7echo.
-
8echo Choice 1 ("Choice 1" can be renamed to whatever you want, any of the choices)
-
9echo Choice 2
-
10echo Choice 3 (Keep doing that until you have all of the choices that you need.)
-
11Type "set /p choice=(Insert question or command here, like "Yes or no?")
-
12if not '%choice%'== set choice=%choice:~0,1%
-
13if '%choice%'=='1' goto :choice1
-
14if '%choice%'=='2' goto :choice2
-
15(Continue doing this pattern until you have enough. Then type:)
-
16echo "%choice%" is not a valid option. Please try again.
-
17echo.
-
18goto start
-
19
-
20(commands you want to run)
-
21
-
22(commands)
-
23
-
24(commands)
-
25goto end
-
26
-
27pause
-
28exit
-
29Save this as a .bat file. Double click to test your batch file.
Advertisement
Community Q&A
-
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."
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
Warnings
- Command that are used without knowledge may harm your computer.⧼thumbs_response⧽
- Do not use commands unless you know what you are doing.⧼thumbs_response⧽
Advertisement
You Might Also Like
How to
Become a Programmer
How to
Learn a Programming Language
How to
Format Text as Code in Discord
How to
Run a Program from the Command Line on Linux
How to
Convert from Binary to Decimal
How to
Download a File from GitHub
How to Factory Reset a Schlage Lock & Restore the Default Programming Code
How to Delay a Batch File: Timeout, Pause, Ping, Choice & Sleep
How to
View Source Code
Learn to Write Pseudocode: What It Is and Why You Need It
How to Change 4-Digit User Codes on Schlage Locks
How to
Code
How to
Make an Exe File
3 Ways to Download GitHub Directories and Repositories
Advertisement
About This Article
Tested by:
wikiHow Technology Team
wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, 13 people, some anonymous, worked to edit and improve it over time. This article has been viewed 239,622 times.
How helpful is this?
Co-authors: 13
Updated: July 11, 2022
Views: 239,622
Categories: Programming
Advertisement