Batch File To Loop Menu


  1. Posts : 10
    Windows 7 64-Bit
       #1

    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 Computer


  2. Posts : 10
    Windows 7 64-Bit
    Thread Starter
       #2

    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 Computer


 

  Related Discussions
Our Sites
Site Links
About 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 22:47.
Find Us