Create a multiple choice menu in a batch-file
There are endless possibilities to this, so what I’m about to show you will only cover a few bases that will point you in the direction you might want to go.
First up a few definitions
- Goto: The Goto Statement allows us to jump to a specific part of the script, like back to Start or the end.
- [Place]: When we use the Goto Statement we need a target. The Target or Place is defined by a Colon and a name (:HOME).
- Variables (or Var): Variables are small post-it notes that stores information (user input) for later use. In Batch Scripting we declare a variable with the SET command.
- ECHO: This Command is used to hide or show feedback to the user. Turning it OFF will make sure everything we do is invisible to the user.
- CLS: Clear Screen, empties the CMD-window
- Pause: Inserting the PAUSE command will pause the script from running until the user press a key.
- START or CALL: Commands used to trigger an event (a batch file, website etc)
- Exit: This command ends the script from running
Onto the Script
Open Notepad and enter the following code:
@echo off
 title Multiple Choice Menu
 :home
 cls
 echo.
 echo Select a task:
 echo =============
 echo.
 echo 1) Open www.mintywhite.com
 echo 2) List Temp-files
 echo 3) Run IpConfig.exe
 echo 4) Run CleanUp.Bat
 echo 5) Exit
 echo.
 set /p web=Type option:
 if "%web%"=="1" start www.mintywhite.com
 if "%web%"=="2" goto list
 if "%web%"=="3" start ipconfig.exe
 if "%web%"=="4" Call cleanup.bat
 if "%web%"=="5" exit
 goto home
 :list
 echo Listing files from c:\windows\temp
 dir c:\windows\temp /p /b
 Pause
 goto homeSave the document as
Menu.bat
 Then Create another bat-file, call it cleanup.bat and save it in the same folder as the above.Copy this code into it:
echo Removing Temp-files from c:\windows\temp
 echo Note! If you get an error, you need to run
 echo this with administrative privileges.
 cd\
 cd\windows\temp
 Del *.tmp /Q
 PauseThanks to http://mintywhite.com  
 
No comments:
Post a Comment