13-07-2010, 02:23 AM
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.
This basically hides all of the background code, stopping it from showing on the screen, keeping it clean.
STEP 2
Then underneath that, type.
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.
This sets a title, making the top of the Window say "Batch menu".
STEP 4
Next,
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.
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,
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
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,
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.
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.