How to create options or choices in a batch file

Table of contents:

How to create options or choices in a batch file
How to create options or choices in a batch file
Anonim

Are you really good at programming batch files, just don't know how to make menus with a Yes, No, or Choice 1, 2, or 3? You've come to the right place!

Steps

Create Options or Choices in a Batch File Step 1
Create Options or Choices in a Batch File Step 1

1 Click Start> Run

Create Options or Choices in a Batch File Step 2
Create Options or Choices in a Batch File Step 2

2 Enter "cmd" (without quotes)

Create Options or Choices in a Batch File Step 3
Create Options or Choices in a Batch File Step 3

3 Enter "edit"

Create Options or Choices in a Batch File Step 4
Create Options or Choices in a Batch File Step 4

Step 4. Enter the following commands

After each press enter. Anything in brackets does NOT need to be entered, these are notes with explanations.

Create Options or Choices in a Batch File Step 5
Create Options or Choices in a Batch File Step 5

5 @echo off (This command will 'hide' the ability to enter commands - optional, but we recommend using it)

Create Options or Choices in a Batch File Step 6
Create Options or Choices in a Batch File Step 6

6 cls (Hide everything above - optional, but if you want everything to look orderly - we recommend)

Create Options or Choices in a Batch File Step 7
Create Options or Choices in a Batch File Step 7

7: start

Create Options or Choices in a Batch File Step 8
Create Options or Choices in a Batch File Step 8

Step 8.echo.

Create Options or Choices in a Batch File Step 9
Create Options or Choices in a Batch File Step 9

9 echo Choice 1 ("Choice 1" can be renamed as needed)

Create Options or Choices in a Batch File Step 10
Create Options or Choices in a Batch File Step 10

10 echo Choice 2

Create Options or Choices in a Batch File Step 11
Create Options or Choices in a Batch File Step 11

Step 11. echo Choice 3 (Insert as many choices as you need)

Create Options or Choices in a Batch File Step 12
Create Options or Choices in a Batch File Step 12

Step 12. Enter "set / p choice = (Insert a question or command here, for example" Yes or no?

")

Create Options or Choices in a Batch File Step 13
Create Options or Choices in a Batch File Step 13

Step 13.if not '% choice%' == set choice =% choice

~0, 1%

Create Options or Choices in a Batch File Step 14
Create Options or Choices in a Batch File Step 14

14 if '% choice%' == '1' goto: choice1

Create Options or Choices in a Batch File Step 15
Create Options or Choices in a Batch File Step 15

15 if '% choice%' == '2' goto: choice2

Create Options or Choices in a Batch File Step 16
Create Options or Choices in a Batch File Step 16

Step 16 (Continue with this example until you reach the number of options you want

Then enter:)

Create Options or Choices in a Batch File Step 17
Create Options or Choices in a Batch File Step 17

Step 17. echo "% choice%" is not a valid choice

Please try again.

Create Options or Choices in a Batch File Step 18
Create Options or Choices in a Batch File Step 18

Step 18.echo.

Create Options or Choices in a Batch File Step 19
Create Options or Choices in a Batch File Step 19

19 goto start

Create Options or Choices in a Batch File Step 20
Create Options or Choices in a Batch File Step 20

Step 20. After that enter:

Create Options or Choices in a Batch File Step 21
Create Options or Choices in a Batch File Step 21

21: choice1

Create Options or Choices in a Batch File Step 22
Create Options or Choices in a Batch File Step 22

22 (commands to execute)

Create Options or Choices in a Batch File Step 23
Create Options or Choices in a Batch File Step 23

23 goto end

Create Options or Choices in a Batch File Step 24
Create Options or Choices in a Batch File Step 24

24: choice2

Create Options or Choices in a Batch File Step 25
Create Options or Choices in a Batch File Step 25

25 (commands)

Create Options or Choices in a Batch File Step 26
Create Options or Choices in a Batch File Step 26

26 goto end

Create Options or Choices in a Batch File Step 27
Create Options or Choices in a Batch File Step 27

27: choice3

Create Options or Choices in a Batch File Step 28
Create Options or Choices in a Batch File Step 28

28 (teams)

Create Options or Choices in a Batch File Step 29
Create Options or Choices in a Batch File Step 29

29 goto end

Create Options or Choices in a Batch File Step 30
Create Options or Choices in a Batch File Step 30

Step 30. Continue until you have entered the number of commands you need.

Create Options or Choices in a Batch File Step 31
Create Options or Choices in a Batch File Step 31

31: end

Create Options or Choices in a Batch File Step 32
Create Options or Choices in a Batch File Step 32

32 pause

Create Options or Choices in a Batch File Step 33
Create Options or Choices in a Batch File Step 33

33 exit

Create Options or Choices in a Batch File Step 34
Create Options or Choices in a Batch File Step 34

34 Save as a.bat file

To check the batch file, double click on it.

Example

@ECHO off cls: start ECHO. ECHO 1. Print Hello ECHO 2. Print Bye ECHO 3. Print Test set / p choice = Enter a number to output the text. rem if not '% choice%' == '' set choice =% choice: ~ 0; 1% (do not use this command as it only takes the first digit if you enter several. For example, if you enter the number 23455666, it will be only number 2 is selected and you get "bye" if '% choice%' == '' ECHO "% choice%" is not a valid option, 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

Advice

  • For more information, enter in the command line / help.

  • You can change: choice1 to any other word, but stick to it until the end of the file.
  • For more information, enter in the command line choice / ?.

  • Command line editor does not work in Windows 8. These commands are available for windows XP / Vista / Windows 7.

Warnings

  • If you are unsure of what you are doing, do not use commands.
  • Commands you use thoughtlessly can damage your computer.

Popular by topic