Create Options or Choices in a Batch File

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

  1. Click Start>Run
  2. Type "cmd" (no quotations)
  3. Type "edit"
  4. 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.
  5. @echo off (This command will 'hide' the command input - optional but recommended)
  6. cls (This will clear anything above - optional but recommended if you're wanting to make it look neat)
  7.  :start
  8. echo.
  9. echo Choice 1 ("Choice 1" can be renamed to whatever you want, any of the choices)
  10. echo Choice 2
  11. echo Choice 3 (Keep doing that until you have all of the choices that you need.)
  12. Type "set /p choice=(Insert question or command here, like "Yes or no?")
  13. if not '%choice%'== set choice=%choice:~0,1%
  14. if '%choice%'=='1' goto :choice1
  15. if '%choice%'=='2' goto :choice2
  16. (Continue doing this pattern until you have enough. Then type:)
  17. echo "%choice%" is not a valid option. Please try again.
  18. echo.
  19. goto start
  20. After that you type:
  21.  :choice1
  22. (commands you want to run)
  23. goto end
  24.  :choice2
  25. (commands)
  26. goto end
  27.  :choice3
  28. (commands)
  29. goto end
  30. Continue doing this pattern until you have completed the file.
  31.  :end
  32. pause
  33. exit
  34. Save this as a .bat file. Double click to test your batch file.

Example

Tips

  • Type choice /? in the Command Prompt for more info.
  • Type /help in the Command Prompt for more info.
  • You can rename :choice1 or any others to whatever you like, as long as you keep it the same throughout the entire file.
  • Edit command in command prompt does not work in Windows 8. This command is available for windows XP/Vista/Windows 7.

Warnings

  • Command that are used without knowledge may harm your computer.
  • Do not use commands unless you know what you are doing.

Related Articles