Tuesday, 28 August 2012

How to create a menu in batch file

Today we can involve in some batch coding.Batch files are simple programs that are executed by CMD.

Batch file is simple and light compared to other programming languages.But remember it is not as powerful as those! But! batch files are able to carry programs that can Shut your PC,or to control others system and execute Viruses! .So, we can't call it less powerful either.!

It is quite easy to use.Basic coding doesn't need much experience but there are lot's of complex programs as i said.It does requires some knowledge and skill.

In this post we are dealing with a basic program.

The main thing is you just need to know the basic commands used in batch that could be easily studied without much effort.

So now let's come to our title...this is a simple way of creating a menu in batch.

This batch can be used to open various files in your computer.

Copy down the code in notepad and save it as .bat.Bat is the extension we us to save batch files.we can also save batch files using one more extension - .cmd.

This is a sample code.

@echo off
color 0a
echo Windows Menu
echo ************
echo 1. Notepad
echo 2. Calculator
echo 3. Paint
echo 4. Task manager
echo 5. Exit
echo ****************               *** Futurebrain ***
set /p brain=
if %brain%== 1 start notepad.exe
if %brain%== 2 start calc.exe
if %brain%== 3 start mspaint.exe
if %brain%== 4 start taskmgr.exe
if %brain%== 5 goto 3
echo Thank you for using              
echo                                *** Futurebrain ***

This is how the program works.The above programs are just examples.You can execute any programs using this method.Just use the link of the program and copy down it.

1. set /p  -  The /P switch allows you to set a variable equal to a line of input entered
                  by the user.
                  The Prompt string is displayed before the user input is read.
                  As I  wrote above  set /p brain=  is used as prompt string
                  we have set  BRAIN as the prompt code and any value given to Brain is 
                  if %brain%==  command is used for assigning value to set /p brain.

2.Echo -  echo command determines what is shown on the screen.It can be used to show
               anything on the screen and also to show nothing! For example,

               echo This is an example  >>this gets displayed on the screen.
               echo.                                 >> this is used as a line break code.

So a single code can be used for multiple purpose.

As i already said,This post is just an example on creating a batch file.This is NOT the only way to create a menu in batch.There are a various other ways to create a menu.This post was only meant to make you understand how these basic codes work within the program.So , just don't copy the code alone,try to understand and use your own methods to create awesome files using Batch.! Its quite interesting to work with these kind of programs.

Hope you enjoyed this post.!


  1. really good piece of information, I had come to know about your site from my friend shubodh, kolkatta,i have read atleast nine posts of yours by now, and let me tell you, your site gives the best and the most interesting information. This is just the kind of information i would regularly watch out for the new posts, once again hats off to you! Thanks a lot once again, Regards, How to create batch file


Feel Free to Comment