Example:
@echo off goto menu1 :menu1 cls echo Menu 1 echo. echo Press "1" to start control panel echo. echo Press "2" to go to second menu echo. choice /c 12 if errorlevel ==2 goto menu2 if errorlevel ==1 goto control panel :menu2 cls echo Menu 2 echo. echo Press "1" start msconfig echo. echo Press "2" to go to first menu echo. choice /c 12 if errorlevel ==2 goto menu1 if errorlevel ==1 goto msconfig :control panel cls start control goto menu1 :msconfig cls start msconfig goto menu1 So if Im in menu1 and I press 2 it will go to menu2.
If Im in menu2 and I press 2 it will go to menu1,
but if Im in menu2 and I press 1 to open msconfig, it instead opens control panel in menu1 while menu2 is still opened, why is this?
21 Answer
To do this you can (should) to use the if command and not error level. You will also need to get user input to a variable like this, set /p examplemenu1= Enter your choice^> That will insert what the user has chosen to examplemenu1, then you use the if command.
I will show you a better way to write a menu and fix your problem. In this menu if someone enters nothing, nothing will happen.
@echo off :start :menu1 cls echo. echo. echo Enter 1 and Press Enter to open control panel echo. echo Enter 2 and Press Enter to go menu 2 echo. set /p menu1= Enter your choice then Press Enter^> if "%menu1%" EQU "1" goto :open-control if "%menu1%" EQU "2" goto :menu2 goto :menu1 :menu2 Cls REM I will do the basics echo Menu 2 echo Type 1 to open msconfig echo. echo Type 2 to go back to menu 1 echo. set /p menu2= Enter your choice and press enter^> if "%menu2%" EQU "1" goto :open-msconfig if "%menu2%" EQU "2" goto :menu1 goto :menu2 :open-control cls start control REM People will ping a invalid host to wait REM But they don't know that you can just use localhost ping localhost -n 3 >nul goto :start :open-msconfig Cls start msconfig ping localhost -n 3 >nul goto :start Test this out and reply if it works for you.
1