How to create an interactive menu in a Windows batch script

Last update: 30/04/2025

  • Batch menus automate tasks and simplify workflows in Windows.
  • They can be easily customized and adapted to the user's needs.
  • They are useful for both beginners and professionals in development and administration.
How to create a menu in a batch script

How to make a menu in a batch script? Menus in Windows batch scripts are a powerful and simple tool for automating tasks, improving efficiency, and facilitating repetitive command use. With a well-designed menu, any user can execute actions by simply pressing a number or letter, eliminating errors and speeding up processes. Creating a custom menu may sound complicated, but with proper instructions, it's accessible even for those with no prior programming experience.

In this article I'm going to show you How to make the most of menus in batch scripts, both in domestic and professional environments. I compile and detail The best techniques, practical examples and tips that I have extracted from specialized websites and real experiences. If you are looking for a complete and clear guide, here is everything you need to Learn how to create, customize, and take advantage of batch menus in Windows..

What is a menu in a batch script and what is it used for?

How to create a menu in a batch script

A batch menu allows you to present various options to the user, who can choose by pressing a key or typing a number. The script then executes the associated action automatically. This dynamic is very useful for recurring tasks or environments with multiple users with different profiles.

Its use is very common in technical environments where it is necessary to compile projects, run tests, delete files, launch applications or organize routine actions without having to remember each specific command. Menus also help document tasks and make the work environment more user-friendly., reducing the learning curve by integrating all essential operations into a single file.

The origin of batch scripts dates back to the days of MS-DOS and punch cards, when automating tasks was a major advancement. Today, although operating systems have evolved significantly, Batch scripts are still useful for orchestrating actions and improving productivity..

Why is it worth creating a batch menu?

Organizing your batch scripts with a menu offers many advantages, both for individual users and development teams. According to the experience of professionals and the most highly rated resources:

  • Streamline repetitive tasks: You can quickly compile, run, clean, test, and deploy projects without memorizing commands.
  • It facilitates teamwork: All members of a project can use the same menu, making it easy to learn and share.
  • You don't need to install anything extra: : Just have the script in your project folder, and it will work on any Windows.
  • Simplify documentation and maintenance: The menu serves as a clear reference for the most common operations and can be versioned alongside the source code.
Exclusive content - Click Here  TikTok receives historic $600 million fine for failing to protect European user data from China

The learning curve is minimal and once the menu is created, anyone can safely perform complex tasks.You can even port these menus to Unix systems using shell script, although we'll focus on the Windows environment here.

Basic elements for creating a batch menu

To understand how a batch menu works, you first need to know the fundamental elements of the batch scripting language:

  • Tags and jumps (:, goto): Labels identify sections of code. The command goto allows you to jump between sections depending on the option chosen by the user.
  • User input (set /p): Allows you to collect what the user types and store it in a variable.
  • Conditionals (if): They evaluate the options entered by the user to execute the appropriate actions.
  • System commands: From changing directories, creating folders, clearing screen (cls), to run additional applications or scripts.

With these ingredients, you can create everything from simple menus to full-blown dashboards for any task.

Basic Batch Menu Example: Step by Step

Windows backup batch script

Let's look at a simple menu example to get started, ideal for understanding the logic and how to adapt it to your needs. The following snippet shows how to create a menu with three options: display a puzzle, create a directory, and exit.

@echo off title Options menu :menu echo Choose one of the following options: echo. echo 1) Puzzle echo 2) Create directory echo 3) Exit echo. set /p option= if %option%==1 goto puzzle if %option%==2 goto newfolder if %option%==3 goto exit :puzzle echo What is something and nothing at the same time? pause goto menu :newfolder echo Creating new folder... mkdir puzzle pause cls goto menu :exit echo Closing program... pause

This menu uses labels to organize options and the goto command to jump between them.. Every time the user makes a decision, the script reacts immediately and allows them to return to the home menu or exit the program. If you want to go deeper, we'll show you how in this guide. How to write batch scripts to automate tasks in Windows.

Exclusive content - Click Here  How to Disable Windows 10 Security

How to structure advanced menus in batch

Windows backup batch script

When needs grow, a simple menu can fall short. That's why many professional projects employ batch menus that integrate dozens of options, including submenus and the execution of external commands such as Maven, web browsers, or tools specific to the development environment.

For example, a developer batch menu can launch builds, run unit tests, clean up local repositories, open browsers to predefined addresses, or launch application servers, all managed from a versioned batch file alongside the source code.

These files typically include loops to display the menu over and over, variables to store the user's selection, and checks to prevent errors from incorrect input. The flexibility is such that you can replicate almost any common command interface.

A real-life example: batch menu to automate project tasks

A highly valued example in professional development environments is the following menu, which organizes the most common tasks within version-controlled projects and tools like Maven. The menu allows you to compile, clean, run, and launch web applications, automatically opening the browser when necessary:

@echo off echo ############################################################ echo . echo . menu.bat Menu for simple task execution echo . echo ## ... ------------------------------------------- set OPTION=1 SET CHOICE=:menu SET CHOICES= set LABEL=compileClean set TEXT=Compile and clean projects set KEY=1 if "%CHOICE%"=="" echo . %KEY%. %TEXT% if "%OPTION%"=="%CHOICE%" start %CD%\menu.bat %LABEL% set CHOICES=%CHOICES%%KEY% set /a "OPTION+=0" REM ---- Add more options here according to your needs ---- echo . choice /C %CHOICES% set CHOICE=%errorlevel% set OPTION=1 goto menu_start :subcommands goto %1 :compileClean call mvn clean install goto end :end pause exit

This type of batch menu is highly modifiable: You just need to copy the option block, change the commands to execute, and adapt the variables to suit your project. You can add as many options as you want, and even submenus if your project grows.

Batch menu customization and color management

One of the advantages of batch menus is that you can customize them visually. Using the command colorYou can give each option different styles. The hexadecimal color code in batches allows for a wide variety, with the first digit indicating the background color and the second the text color. Let's look at some examples:

  • 0 = Black
  • 1 = Blue
  • 2 = Green
  • 3 = Aquamarine
  • 4 = Red
  • 5 = Purple
  • 6 = Yellow
  • 7 = White
  • 8 = Gray
  • 9 = Light blue
  • A = Light green
  • B = Light Aquamarine
  • C = Light red
  • D = Light purple
  • E = Light yellow
  • F = Bright white
Exclusive content - Click Here  Como Obtener El Numero De Seguro Social

This way you can highlight options, display error messages, or indicate the result of each action with different colors.improving the user experience.

Instructions for creating and saving your batch menu

Creating and saving a batch menu is simple. You just need to follow a few basic steps:

  • Choose your favorite text editor. Notepad or Notepad++ are more than enough.
  • Copy and paste the base code of the menu, adapting the options and actions to what you need.
  • Save the file with a .bat or .cmd extension. For example: menu.bat.
  • Double-click in the file and test the menu. You'll see how it responds to your selections.

Remember: You can add as many commands and functions as you want, from running other scripts or utilities, to launching programs or opening files automatically. Reducing the size of images can also be helpful. if you want to optimize the visual environment of your scripts.

Best practices and extra tips for robust batch menus

To get the most out of your batch menus, it's a good idea to keep in mind some things: tips and tricks which will increase its usefulness and robustness:

  • Always validate user input: If someone types an option out of range, it displays an error message and asks for the selection again.
  • Use environment variables to save routes, settings, or parameters that change between projects.
  • Version your menu along with the source code in team projects so that everyone works in the same way.
  • Document the options with clear comments within it itself script.
  • Prepare submenusIf your menu has many options, you can create categories and submenus to avoid cluttering the home screen.
  • Make it cross-platform if you need to: You can port the logic to a Linux or Unix shell with minor syntax changes.

With these tricks, your batch menu will be much more efficient, easier to use, and adaptable to new needs.

This type of effective and flexible solution for automating tasks in Windows allows for everything from the most basic to complex development environments. Take advantage of the simplicity of the code, the ease of customization, and the ability to group any command you use every day. This way, you'll gain productivity and reduce potential errors, all in a single file. We hope you now know how to create a menu in a batch script.