Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Batch File To Loop Menu

14 Dec 2015   #1
JBourne

Windows 7 64-Bit
 
 
Batch File To Loop Menu

I'm creating a batch file that will launch when I login to my user account. I followed this tutorial to create a batch file with a menu. It works, however, if the user enters a number that is not listed, I want it to go back to the menu. How would I implement that?

Side note: I understand I could use something more flexible like Powershell, however, I prefer batch files.

Here is what I have so far:

Code:
@ECHO OFF
CLS
:MENU
echo Welcome %USERNAME%

echo 1 - Start KeePass
echo 2 - Backup
echo 3 - Exit

SET /P M=Type 1,2,3 then press Enter:


IF %M%==1 GOTO StarKeePass
IF %M%==2 GOTO Backup
IF %M%==3 GOTO EOF


:StarKeePass
SET keePass="%USERPROFILE%\KeePass\KeePass-2.30\KeePass.exe"
SET kdb="%USERPROFILE%\KeePass\PasswordDatabase\PasswordDatabase.kdbx"

echo I'll start KeePass for You
START "" %keePass% %kdb% 

GOTO MENU

:Backup
SET backup="%USERPROFILE%\backup.bat"
call %backup%

GOTO MENU



My System SpecsSystem Spec
.
14 Dec 2015   #2
JBourne

Windows 7 64-Bit
 
 

Found a solution:

Code:
@ECHO OFF
CLS


:MENU
echo Welcome %USERNAME%

echo 1 - Start KeePass
echo 2 - Backup
echo 3 - Exit

SET /P M=Type 1,2,3 then press Enter:


IF %M%==1 GOTO StarKeePass
IF %M%==2 GOTO Backup
IF %M%==3 GOTO :EOF
GOTO MENU


:StarKeePass
SET keePass="%USERPROFILE%\KeePass\KeePass-2.30\KeePass.exe"
SET kdb="%USERPROFILE%\KeePass\PasswordDatabase\PasswordDatabase.kdbx"

echo I'll start KeePass for You
START "" %keePass% %kdb% 

GOTO MENU

:Backup
SET backup="%USERPROFILE%\backup.bat"
call %backup%

GOTO MENU
Put a GOTO MENU after the if statements
My System SpecsSystem Spec
Reply

 Batch File To Loop Menu




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
Batch file help. For loop not working...
What im trying to accomplish: -I want to REG QUERY a registry entry that will output the value of a (*SpeedDuplex) string value -I then want to store that value in a variable The command im using and the output: REG QUERY...
General Discussion
How to run a batch file at logoff & some batch scripting help please
Hiya, I'd just like to run a simple batch file at logoff to backup some settings. I plan to use Robocopy, which is what i use to more thorough backups. Two questions: 1. How make it run by clicking Start > Shutdown? (i realise i could make a shutdown batch file and run it instead, but i'd...
Backup and Restore
Launch batch file from the context menu in admin mode
Hi, I found a registry script that creates an option on the windows explorer context menu that allows you to run a batch file. The program that I use within the batch file is producing an access denied error which I dont get if I run the batch file normally. I wondered if this was something to...
General Discussion
Batch File that grabs file names from folder to insert into batch file
Ok I'm totally at a loss on how to word this so I'm just going to write it out the best that I can... :confused: First I have a batch file that I'm writing that will convert mp4 files to mp3 files (I have a lot) for a buddies band using ffmpeg. Here's the code that I'm using: ffmpeg -i...
General Discussion
In need of help doing a FOR /F Do loop in a CMD Batch
I am in need of help doing a FOR /F Do loop in a CMD Batch script. I am trying to write a batch script that will ping all IP addresses in a host file except for an IP address that starts with 127 and skip all commented lines in the hostfile or that start with a #. my current code will ping...
General Discussion
New Batch File - Add to Context Menu
How to Add "New Batch File" to the Context Menu in Windows This will show you how to add Windows Batch File to the right click "New" context menu to make creating a new BAT file easier for all users in Vista, Windows 7, and Windows 8. You will need to be logged in as an administrator to be...
Tutorials


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 04:50.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App