• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to make a menu in batch (And start processes)
#1
This is a tutorial on how to make a menu in batch. In this example we'll be using it to open up Internet explorer.

If you just want to recap, or want the complete code simply copy it from the spoilers below.

[spoiler]
[code=batch]
@echo off
:menu
title Batch menu
echo To open internet explorer type: Internet
echo.
set choice=
set /p choice=What would you like to open?:
if '%choice%'=='Internet' goto 1
msg * Error: input not recognised, please try again.
cls
goto menu
:1
cls
echo Opening Internet explorer..
start iexplore.exe
pause
cls
goto menu
[/code]
[/spoiler]


OK, lets start.

STEP 1

Open up notepad, or a text editor of your choice and type.

Code:
@echo off

This basically hides all of the background code, stopping it from showing on the screen, keeping it clean.

STEP 2

Then underneath that, type.

Code:
:menu

This sets a variable. The word "menu" becomes an object that can be recalled later, this allows us to be able to go back to it.

STEP 3

Next type.

Code:
title Batch menu

This sets a title, making the top of the Window say "Batch menu".

STEP 4

Next,

Code:
echo To open internet explorer type: Internet
echo.

This display the message "To open internet explorer type: Internet" at the top of the command prompt. The "echo." basically creates a line break from the next line.

STEP 6

This next step is important.

Code:
set choice=
set /p choice=What would you like to open?:

This is the code, that sets the availability of typing in the menu! The part that says, "What would you like to open?:", is what message is displayed before you type, on the same line you type. You can change it to whatever you want.

STEP 7

Then,

Code:
if '%choice%'=='Internet' goto 1

If you type "Internet" it goes to 1, basically it runs the command "1" which we are going to define in a minute.

STEP 8

Code:
msg * Error: input not recognised, please try again.
cls
goto menu

If you input anything other than "Internet" you'll receive a pop up containing that message. cls means that it'll clear the screen and then go back to the menu, allowing you to retry.

STEP 9

Lastly,

Code:
:1
cls
echo Opening Internet explorer..
start iexplore.exe
pause
cls
goto menu

This sets the variable 1, when 1 is run it'll open up Internet explorer.

It then clears the screen and displays the message "Opening Internet explorer..", after that it'll open iexplore.exe, then pause then once a button is pressed it'll clear the screen and go back to the menu.

STEP 10

Simply save the document as .bat file, then run it.
  Reply
#2
Other than what i said on msn the only other thing is your 'Msg *' only works in windows XP, not vista nor 7 Smile
  Reply
#3
I don't really know very much batch, is there a method that works in Vista / 7 or has it been disabled?
  Reply
#4
Its been disabled i think, its been a while since i was Mr Batch Tongue
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  (Batch) Useful batch commands Mark 10 31,712 13-02-2011, 02:42 PM
Last Post: Mark
  (Batch) How to shutdown a computer using a batch file Mark 0 6,872 22-05-2010, 10:49 PM
Last Post: Mark
  (Batch) Autostarting programs on login Mark 0 5,411 22-05-2010, 10:44 PM
Last Post: Mark
  (Batch) Hello world - Your first Batch program Mark 0 6,896 22-05-2010, 10:35 PM
Last Post: Mark

Forum Jump: