howtothings.co.uk
How to make a menu in batch (And start processes) - Printable Version

+- howtothings.co.uk (https://www.howtothings.co.uk)
+-- Forum: Computing (https://www.howtothings.co.uk/forumdisplay.php?fid=4)
+--- Forum: Programming Support, Graphic Design and Tutorials (https://www.howtothings.co.uk/forumdisplay.php?fid=14)
+--- Thread: How to make a menu in batch (And start processes) (/showthread.php?tid=242)



How to make a menu in batch (And start processes) - Mark - 13-07-2010

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.


RE: How to make a menu in batch - Jamez247 - 13-07-2010

Other than what i said on msn the only other thing is your 'Msg *' only works in windows XP, not vista nor 7 Smile


RE: How to make a menu in batch - Mark - 13-07-2010

I don't really know very much batch, is there a method that works in Vista / 7 or has it been disabled?


RE: How to make a menu in batch - Jamez247 - 13-07-2010

Its been disabled i think, its been a while since i was Mr Batch Tongue