Batch-Files are small yet powerful tools that you can create to easy your daily chores. Back in the day when Windows was glass covered holes for letting air and light into your house, Batch scripting was an essential and every day tasks. Today, most people don’t even know it exists.
This time we’ll explore how to create a multiple choice menu that can trigger files, website and functions.
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
This script will do many things (to show you it’s possible). Under normal circumstances you would create separate scripts for different functionality or tasks.
Open Notepad and enter the following code:
title Multiple Choice Menu
echo Select a task:
echo 1) Open www.mintywhite.com
echo 2) List Temp-files
echo 3) Run IpConfig.exe
echo 4) Run CleanUp.Bat
echo 5) Exit
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
echo Listing files from c:\windows\temp
dir c:\windows\temp /p /b
Save 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.
Del *.tmp /Q
Good luck to you. Should you have any questions about this, don’t hesitate to contact me here on in the Forum.