What is wrong with this IF NOT statement? - batch-file

This code is supposed to make it so that if I press 1 - 4 it would go the the options 1 - 4 and if i press something else it would say that its not an option. But if I type something else it goes to debug anyway.
And I've checked the code several times and I can't find an error. I even compared it to a code like this that actually worked and I even Ctrl-c Ctrl-v'ed it and it still won't work.
:admin
cls
color %debug%
echo You have accessed the admin debug menu
echo Do what you wan't
echo [1] Set Debug color
echo [2] Set Default color
echo [3] Set Warning color
echo [4] Exit
set /p "lol=> "
IF /i %lol%==1 goto dbg if NOT goto 9
IF /i %lol%==2 goto dfc if NOT goto 9
IF /i %lol%==3 goto wnc if NOT goto 9
IF /i %lol%==4 goto start if NOT goto 9
:dbg
cls
color %debug%
echo Set Debug color
set /p "debug=> "
echo Debug color set to %debug%
color %debug%
pause
goto admin
:dfc
cls
color %debug%
echo Set Default color
set /p "default=> "
echo Default color set to %default%
pause
goto admin
:wnc
cls
color %debug%
echo Set Warning color
set /p "warning=> "
echo Warning color set to %warning%
pause
goto admin
:9
cls
color %warning%
echo This is not a viable option!
ping localhost -n 5 >nul
goto admin
I test it out and when i type ex 5 it still goes to debug.

You should take a closer look at how IF statements work.
E.g. this line IF /i %lol%==1 goto dbg if NOT goto 9 makes absolutely no sense.
Your code should look something like this:
...
set /p "lol=> "
IF /i "%lol%"=="1" goto dbg
IF /i "%lol%"=="2" goto dfc
IF /i "%lol%"=="3" goto wnc
IF /i "%lol%"=="4" goto start
cls
color %warning%
echo This is not a viable option!
ping localhost -n 5 >nul
goto admin
...

IF /i %lol%==4 (goto start) else goto 9
Although it's normal practise to use
IF /i "%lol%"=="4" (goto start) else goto 9
which provides some protection against no entry or an entry containing spaces.

try this code
IF /i %lol%==1
(goto dbg)
IF /i %lol%==2
(goto dfc)
IF /i %lol%==3
(goto wnc)
IF /i %lol%==4
(goto start)
else
(goto 9)

Related

I'm trying to create an admin "login" on batch and it just closes the cmd

I am trying to make an "admin" login and it isn't working.
#echo off
title RPG BETA
color 0b
set /p player=Welcome to Xero, what's your name?:
if %player% == Admin goto admin
:intro
echo Hello %player%!
pause
goto start
:admin
set /p password:What is the admin password?:
if %password% == Insertanypassword goto true
if %password not insertanypassword goto false
:true
cls
echo Welcome, Admin!
set /p af=Would you like to enable admin features?[y/n]:
if %af% == y goto true1
if %af% == n goto start
:true1
cls
set CPU=20
set CPUN=Scorpion
set CPUD=3
set gun=9999999
set gund=9999999
set playerh=9999999
goto fight
:start
cls
echo In the distant future, the world was on the brink of destrucion.
timeout 3 >nul
echo In the midst of the wasteland, a single man, named %player%, will overcome the odds
pause
goto BFight
:BFight
cls
set CPU=20
set CPUN=Scorpion
set CPUD=3
set gun=1
set gund=10
set playerh=20
:Fight
cls
if %CPU% leq 0 goto win
if %playerh% == 0 goto lose
cls
echo You encounter a %CPUN%!
echo %CPUN% Health: %CPU%
echo.
echo Your Health: %playerh%
echo [1]Shoot (%gund% damage) (%gun%)
echo [2]Punch (3 damage)
echo [3]Flee
set /p fp=What do you do?
if %fp% == 1 goto gun
if %fp% == 2 goto punch
if %fp% == 3 goto flee
:gun
cls
if '%gun%'=='0' goto egun
set /a gun = gun - 1
echo You fire at the %CPUN%
timeout 4 >nul
echo It hits!
set /a CPU = CPU - gund
pause
goto cpufightp
:punch
cls
echo You punch the %CPUN%
timeout 4 >nul
echo It hits!
set /a CPU = CPU - 3
pause
goto cpufightp
:egun
echo You have no bullets!
pause
goto Fight
:cpufightp
if %CPU% leq 0 goto win
cls
echo %CPUN% Health: %CPU%
echo.
echo Your Health: %playerh%
pause
cls
goto cpufight
:cpufight
cls
echo The %CPUN% Attacks!
timeout 4 >nul
echo It hits!
set /a playerh = playerh - CPUD
pause
goto fight
:flee
goto losef
:losef
cls echo you have fled
pause
goto suggestion
:lose
cls
echo You died
pause
cls
:win
cls
echo Congradulations, %player%! You win!
pause
cls
:suggestion
set /p suggest=What should I add to Xero?:
echo %player%: %suggest% >> xerosuggest.word
Whenever I type in "Admin" instead of going to the password screen, it just closes cmd, can anyone tell me why? i have experimented with ''s and other commands but I just can't figure it out.
The problem with respect to your specific issue is a typo.
You have:
set /p password:What is the admin password?:
Instead of:
Set /P "password=What is the admin password?: "
The doublequotes are simply good practice, your error was quite clearly that you used a : instead of a =.

GOTO and IF statements aren't working correctly

I have a batch-game where there's some questions for one person in particular, I always change the file when she(the person) isn't nearby so its kind of a surprise.
The thing is I keep on displaying questions of different types but sometimes the GOTO or IF statements just simply doesn't work properly, it just follow the line or exit the file.
#ECHO OFF
setlocal EnableDelayedExpansion
ECHO.
ECHO "i just skipped all this echo for you"
pause>nul
:choice
cls
set /p c=Question 1[y/n]
if /I "%c%" EQU "Y" goto :somewhere
if /I "%c%" EQU "N" goto :somewhere_else
goto :choice
:somewhere
cls
cd "-somewhere in my pc-"
start "-the file-"
cls
goto :somewhere1
:somewhere1
cls
echo.
echo "skip"
pause>NUL
goto :somewhere2
:somewhere2
cls
echo.
set /p c1=question 2
if /I "!c1!"== "option1" goto :correct
if not /I "!c1!"== "option1" goto :somewhere_else1
:correct
cls
echo.
echo "skip"
echo.
echo enter to exit
pause>nul
exit
:somewhere_else1
cls
echo.
echo bad answer
pause>nul
goto :somewhere2
Here are my problems:
When it ask's you the question
:choice
cls
set /p c=Question 1[y/n]
if /I "%c%" EQU "Y" goto :somewhere
if /I "%c%" EQU "N" goto :somewhere_else
goto :choice
it's just work properly, it wasn't working in the past but I magically fixed it with no idea what i'm doing.
but then I just wanted to make it bigger and add the next lines:
:somewhere2
cls
echo.
set /p c1=question 2
if /I "!c1!"== "option1" goto :correct
if not /I "!c1!"== "option1" goto :somewhere_else1
and now the file is executing perfectly the ":correct" part but no the ":somewhere_else1". in the case of ":somewhere_else1" its just exit the file. in the past was exiting the file the right one too but again I fixed it just writing it again.
The problem is your line if not /I "!c1!"== "option1" goto :somewhere_else1
The /I needs to be before not
if /I not "!c1!"== "option1" goto :somewhere_else1
Though I should also mention that your use of ! instead of % is unnecessary in this example.
You should have a read through this link to get some insight into how to fix these errors yourself in the future, and perhaps this link on good practice.

How to auto generate user input choice by found file extensions without manually editing script

I want to recursively search a folder for all exe files and have the batch script automatically set each program.exe file found as a user choice input. It needs to auto-populate the choices appropriately and stop when the last exe is found. So if there are a total of 8 exe files in the searched folder then it would auto output set /p choice of 8 programs.exe's to choose from. Not 9 choices and not 7. The exact number of choices needs to be accurate for all found matches. This is an attempt to streamline the coding process.
I have a massive script I made that will auto populate up to 6 found exe files. There lies my problem. I am capped. The script works well for what it is but I am hoping someone has a trick up their sleve and a new way of thinking about the code execution. I won't lie when I say that this script I made is a bit of a mess. Thanks in advance to anyone who might have some ideas.
Important note: I downloaded and exe program called cecho.exe that helps colorize the terminal output text. I highly recommend using it if you want to debug my script. It would be a giant mess without it. Stick cecho.exe in your system32 folder or whever you want as long as it can be accessed with out needing the full path to the file. I found the program here (https://www.codeproject.com/Articles/17033/Add-Colors-to-Batch-Files)
#echo off
if not "%1" == "max" start /max cmd /i /c %0 max & exit/b
setlocal enabledelayedexpansion
set extension=exe
set nt={\n \t}
set ntt={\n \t \t}
set "TAB= "
:: CECHO RED ::
set cred=cecho {0C}
call :cred
exit /b
:cred
setlocal
echo !cred!
endlocal
:: CECHO GREEN ::
set cgreen=cecho {0A}
call :cgreen
exit /b
:cgreen
setlocal
echo !cgreen!
endlocal
:: CECHO YELLOW ::
set cyellow=cecho {0E}
call :cyellow
exit /b
:cyellow
setlocal
echo !cyellow!
endlocal
:: CHOICE ::
set choice=1
call :choice1
exit/b
:choice1
setlocal
echo !choice!
endlocal
goto start
:start
cls
cd "%~dp0"
call :choice1
exit/b
:choice1
setlocal
set choice=!choice!
endlocal
for /r "." %%i in (*.%extension%) do (
set p!choice!=%%~nxi
set /a choice=!choice!+1
)
echo.
call :cyellow
exit /b
:cyellow
setlocal
!cyellow! ...........................................................%ntt2%
!cyellow! Select a number{\n}
!cyellow! ...........................................................{\n}{#}
endlocal
pause
echo.
set p1=!p1!
call :p1
exit /b
:p1
setlocal
if "%p1%"=="" goto nomatch
if defined p1 (
call :p1
)
:p1
call :cred
call :cgreen
:cred
:cgreen
setlocal
!cred!%ntt%1.
!cgreen! !p1!%ntt%
echo.
set p2=!p2!
call :p2
exit /b
:p2
setlocal
if "%p2%"=="" goto sel_1
if defined p2 (
call :p2
)
:p2
!cred!%ntt%2.
!cgreen! !p2!%ntt%
echo.
set p3=!p3!
call :p3
exit /b
:p3
setlocal
if "%p3%"=="" goto sel_2
if defined p3 (
call :p3
)
:p3
!cred!%ntt%3.
!cgreen! !p3!%ntt%
echo.
set p4=!p4!
call :p4
exit /b
:p4
setlocal
if "%p4%"=="" goto sel_3
if defined p4 (
call :p4
)
:p4
!cred!%ntt%4.
!cgreen! !p4!%ntt%
echo.
set p5=!p5!
call :p5
exit /b
:p5
setlocal
if "%p5%"=="" goto sel_4
if defined p5 (
call :p5
)
:p5
!cred!%ntt%5.
!cgreen! !p5!%ntt%
echo.
set p6=!p6!
call :p6
exit /b
:p6
setlocal
if "%p6%"=="" goto sel_5
if defined p6 (
call :p6
)
:p6
!cred!%ntt%6.
!cgreen! !p6!%ntt%
goto sel_6
echo.
:sel_1
echo.
echo The selected program is !p1!
set "input="
set /p "input=Select a number or type reset to go to beginning:"
if %input%==reset goto startover
if %input%==1 goto ex1
:sel_2
echo.
echo sel_2
set "input="
set /p "input=Select a number or type reset to go to beginning:"
if %input%==reset goto startover
if %input%==2 goto ex2
if %input%==1 goto ex1
:sel_3
echo.
echo sel_3
set "input="
set /p "input=Select a number or type reset to go to beginning:"
if %input%==reset goto startover
if %input%==3 goto ex3
if %input%==2 goto ex2
if %input%==1 goto ex1
:sel_4
echo.
echo sel_4
set "input="
set /p "input=Select a number or type reset to go to beginning:"
if %input%==reset goto startover
if %input%==4 goto ex4
if %input%==3 goto ex3
if %input%==2 goto ex2
if %input%==1 goto ex1
:sel_5
echo.
echo sel_5
set "input="
set /p "input=Select a number or type reset to go to beginning:"
if %input%==reset goto startover
if %input%==5 goto ex5
if %input%==4 goto ex4
if %input%==3 goto ex3
if %input%==2 goto ex2
if %input%==1 goto ex1
:sel_6
echo.
set "input="
set /p "input=Select a number or type reset to go to beginning:"
if %input%==reset goto startover
if %input%==6 goto ex6
if %input%==5 goto ex5
if %input%==4 goto ex4
if %input%==3 goto ex3
if %input%==2 goto ex2
if %input%==1 goto ex1
:ex1
cls
!cyellow! ...............................................{\n}
!cgreen!%ntt% You have chosen{\n}
!cred!%ntt% !p1!{\n}
!cyellow! ...............................................{\n}
timeout 1 >nul
echo.
!cyellow! & set "input=Select [1] to Install or Select [2] to Uninstall:"
set /p "input=!input!"
if %input%==2 goto un1
if %input%==1 goto in1
:ex2
cls
!cyellow! ...............................................{\n}
!cgreen!%ntt% You have chosen{\n}
!cred!%ntt% !p2!{\n}
!cyellow! ...............................................{\n}
timeout 1 >nul
echo.
!cyellow! & set "input=Select [1] to Install or Select [2] to Uninstall:"
set /p "input=!input!"
if %input%==2 goto un2
if %input%==1 goto in2
:ex3
cls
!cyellow! ...............................................{\n}
!cgreen!%ntt% You have chosen{\n}
!cred!%ntt% !p3!{\n}
!cyellow! ...............................................{\n}
timeout 1 >nul
echo.
!cyellow! & set "input=Select [1] to Install or Select [2] to Uninstall:"
set /p "input=!input!"
if %input%==2 goto un3
if %input%==1 goto in3
:ex4
cls
!cyellow! ...............................................{\n}
!cgreen!%ntt% You have chosen{\n}
!cred!%ntt% !p4!{\n}
!cyellow! ...............................................{\n}
timeout 1 >nul
echo.
!cyellow! & set "input=Select [1] to Install or Select [2] to Uninstall:"
set /p "input=!input!"
if %input%==2 goto un4
if %input%==1 goto in4
:ex5
cls
!cyellow! ...............................................{\n}
!cgreen!%ntt% You have chosen{\n}
!cred!%ntt% !p5!{\n}
!cyellow! ...............................................{\n}
timeout 1 >nul
echo.
!cyellow! & set "input=Select [1] to Install or Select [2] to Uninstall:"
set /p "input=!input!"
if %input%==2 goto un5
if %input%==1 goto in5
:ex6
cls
!cyellow! ...............................................{\n}
!cgreen!%ntt% You have chosen{\n}
!cred!%ntt% !p6!{\n}
!cyellow! ...............................................{\n}
timeout 1 >nul
echo.
!cyellow! & set "input=Select [1] to Install or Select [2] to Uninstall:"
set /p "input=!input!"
if %input%==2 goto un6
if %input%==1 goto in6
:in1
cls
set p1=!p1!
call :p1
exit /b
:p1
setlocal
timeout 1 >nul
echo.
echo You are about to Install !p1!
pause
set /p verify=Are you sure you want to Install !p1! (y/[n])?
if /i "%verify%" neq "y" goto startover
start "" !p1!
goto end
:in2
cls
echo You are about to Install !p2!
timeout 1 >nul
echo.
set /p verify=Are you sure you want to Install !p2! (y/[n])?
if /i "%verify%" neq "y" goto startover
start "" !p2!
goto end
:in3
cls
echo You are about to Install !p3!
timeout 1 >nul
echo.
set /p verify=Are you sure you want to Install !p3! (y/[n])?
if /i "%verify%" neq "y" goto startover
start "" !p3!
goto end
:in4
cls
echo You are about to Install !p4!
timeout 1 >nul
echo.
set /p verify=Are you sure you want to Install !p4! (y/[n])?
if /i "%verify%" neq "y" goto startover
start "" !p4!
goto end
:in5
cls
echo You are about to Install !p5!
timeout 1 >nul
echo.
set /p verify=Are you sure you want to Install !p5! (y/[n])?
if /i "%verify%" neq "y" goto startover
start "" !p5!
goto end
:in6
cls
echo You are about to Install !p6!
timeout 1 >nul
echo.
set /p verify=Are you sure you want to Install !p6! (y/[n])?
if /i "%verify%" neq "y" goto startover
start "" !p6!
goto end
:un1
cls
echo You are about to Uninstall !p1!
timeout 1 >nul
echo.
set /p verify=Are you sure you want to Uninstall !p1! (y/[n])?
if /i "%verify%" neq "y" goto startover
start "" !p1!
goto end
:un2
cls
echo You are about to Uninstall !p2!
timeout 1 >nul
echo.
set /p verify=Are you sure you want to Uninstall !p2! (y/[n])?
if /i "%verify%" neq "y" goto startover
start "" !p2!
goto end
:un3
cls
echo You are about to Uninstall !p3!
timeout 1 >nul
echo.
set /p verify=Are you sure you want to Uninstall !p3! (y/[n])?
if /i "%verify%" neq "y" goto startover
start "" !p3!
goto end
:un4
cls
echo You are about to Uninstall !p4!
timeout 1 >nul
echo.
set /p verify=Are you sure you want to Uninstall !p4! (y/[n])?
if /i "%verify%" neq "y" goto startover
start "" !p4!
goto end
:un5
cls
echo You are about to Uninstall !p5!
timeout 1 >nul
echo.
set /p verify=Are you sure you want to Uninstall !p5! (y/[n])?
if /i "%verify%" neq "y" goto startover
start "" !p5!
goto end
:un6
cls
echo You are about to Uninstall !p6!
timeout 1 >nul
echo.
set /p verify=Are you sure you want to Uninstall !p6! (y/[n])?
if /i "%verify%" neq "y" goto startover
start "" !p6!
goto end
:startover
cls
%cgreen% Restarting script from beginning{\n}
timeout 1 >nul
echo.
%cgreen% Try another option{\n}
timeout 1 >nul
goto start
:nomatch
cls
echo.
%cyellow% ...................................................................................................%ntt%
%cyellow% The script found no matching extensions{\n}
%cyellow% ...................................................................................................{\n}
timeout 2 >nul
echo.
%cyellow% ...................................................................................................%ntt%
%cyellow% Make sure to run script in folder with matching extensions{\n}
%cyellow% ...................................................................................................{\n}
timeout 2 >nul
echo.
%cyellow% ...................................................................................................%ntt%
%cyellow% Press any key to exit script{\n}
%cyellow% ...................................................................................................{\n}
timeout /t -1 >nul
goto end
:end
endlocal
exit
So here is a little more automated method, seeing as you are doing pretty much the same with each executable.
#echo off
setlocal enabledelayedexpansion
set cnt=0
for /r %%i in (*.exe) do (
set /a cnt+=1
set "file!cnt!=%%~fi"
call echo [!cnt!] %%file!cnt!%%
)
set /p "ans=::: Please Select Executable from above list by matching number :::: "
choice /C IUC /M "Do you want to [I]nstall, [U]ninstall '!file%ans%!' or [C]ancel'"
if errorlevel 3 goto :eof
if errorlevel 2 (
choice /C YN /M "Are you sure you want to Uninstall '!file%ans%!'"
if errorlevel 2 goto :eof
if errorlevel 1 echo start "" "!file%ans%!" Uninstall procedure here
goto :eof
)
if errorlevel 1 (
choice /C YN /M "Are you sure you want to Install '!file%ans%!'"
if errorlevel 2 goto :eof
if errorlevel 1 echo start "" "!file%ans%!" Install procedure here
goto :eof
)
It will simply list each executable, you select the number corresponding to it, it will ask for install/uninstall and verify once, then in this case it will echo the install/uninstall procedure. You would simply need to modify it to add your actual procedures.. I am showing you the idea, you have to expand it to suit your needs :)

In batch my menu will not work

I was trying to create a simple menu system with batch but i can't tell if it's the 'goto' or the input part that i messed up on. help will be appreciated!
#echo off
cls
echo ==============MENU==============
echo 1.
echo 2.
echo 3.
echo choose.
set/p "menuInput"
if %menuInput%==1 (goto :1)
if %menuInput%==2 (goto :2)
if %menuInput%==3 (goto :3)
else echo error
:1 echo 1
:2 echo 2
:3 echo 3
The syntax of set /p is incorrect. Use set /? to read the help.
The parentheses around (goto :1) don't buy you anything.
The else is both syntactically incorrect (must be on the same logical line as the if) and useless (because if the if had succeeded control would have been passed to :3).
You are missing a bunch of exit /b or goto :eof in order to prevent control falling through the options.
ok i updated your code now this shold work
code here
#echo off
:menu
cls
title menu
echo ==============MENU==============
echo 1.
echo 2.
echo 3.
set /p menuInput=? 1-3
if %menuInput% EQU 1 goto 1
if %menuInput% EQU 2 goto 2
if %menuInput% EQU 3 goto 3
goto error
:1
echo1
pause
:2
echo2
pause
:3
echo3
pause
:error
echo error press 1-3
pause>nul
goto menu
As mentioned by #AlexP,your syntax of set /p is incorrect
you need to use set < space > /p < space > userinput=
and not set/p and there should be = sign after your variable name
SET /P variable=[promptString]
Read More about using SET & IF ELSE and also CHOICE
(edit- removed misleading code for error check)
sample batch with menu using Choice and SET /P IF Else while choosing option from menu.
Example 1 using IF ELSE (input error check)
#echo off
::Your Menu to choose from
:menu
cls
echo ==============MENU==============
echo 1.command menu item 1
echo 2.command menu item 2
echo 3.command menu item 3
echo.
set /p userinput=
if %userinput%==1 (
goto 1
) else if %userinput%==2 (
goto 2
) else if %userinput%==3 (
goto 3
) else (
goto error
)
:1
echo command 1
pause>nul
goto menu
:2
echo command 2
pause>nul
goto menu
:3
echo command 3
pause>nul
goto menu
::Incorrect Input go back to menu
:error
echo Incorrect User Input
pause>nul
goto menu
:end
exit
Example 2 using CHOICE command (no error input check)
#echo off
::Your Menu to choose from
:menu
cls
echo ==============MENU==============
echo 1.command menu item 1
echo 2.command menu item 2
echo 3.command menu item 3
::check and limit user input to selection
choice /C 123 /N /M "Your Selection"
IF "%ERRORLEVEL%"=="1" goto 1
IF "%ERRORLEVEL%"=="2" goto 2
IF "%ERRORLEVEL%"=="3" goto 3
:1
echo command 1
pause>nul
goto menu
:2
echo command 2
pause>nul
goto menu
:3
echo command 3
pause>nul
goto menu
Wrong is set /p.
try set /p menuInput =

batch command input menu

i have a question . It is possible to make a batch menu to accept multiple commands at the same time?
Example : ( my code )
#ECHO OFF
set tries=6
:top
cls
set /a tries=%tries% -1
if %tries%==0 (
goto penalty
)
Echo You have %tries% attempts left.
Echo Please enter your password to proceed
set /p password=
if %password%==Parola ta (
echo Welcome Your Name
ping localhost -n 5 >nul
cls
Echo CONNECTED!
C:
CD\
CLS
:MENU
CLS
ECHO ============= MENU NAME =============
ECHO -------------------------------------
ECHO 1. System Information TXT file
ECHO 2. Selection 2
ECHO 3. Selection 3
ECHO 4. Selection 4
ECHO 5. Selection 5
ECHO 6. Selection 6
ECHO 7. Selection 7
ECHO -------------------------------------
ECHO 8. Selection 8
ECHO -------------------------------------
ECHO 9. Selection 9
ECHO -------------------------------------
ECHO ==========PRESS 'Q' TO QUIT==========
ECHO.
SET INPUT=
SET /P INPUT=Please select a number:
IF /I '%INPUT%'=='1' GOTO Selection1
IF /I '%INPUT%'=='2' GOTO Selection2
IF /I '%INPUT%'=='3' GOTO Selection3
IF /I '%INPUT%'=='4' GOTO Selection4
IF /I '%INPUT%'=='5' GOTO Selection5
IF /I '%INPUT%'=='6' GOTO Selection6
IF /I '%INPUT%'=='7' GOTO Selection7
IF /I '%INPUT%'=='8' GOTO Selection8
IF /I '%INPUT%'=='9' GOTO Selection9
IF /I '%INPUT%'=='Q' GOTO Quit
CLS
ECHO ============INVALID INPUT============
ECHO -------------------------------------
ECHO Please select a number from the Main
echo Menu [1-9] or select 'Q' to quit.
ECHO -------------------------------------
ECHO ======PRESS ANY KEY TO CONTINUE======
PAUSE > NUL
GOTO MENU
:Selection1
systeminfo.exe>systeminfo.txt
ECHO ============INVALID INPUT============
ECHO -------------------------------------
ECHO Please select a number from the Main
echo Menu [1-9] or select 'Q' to quit.
ECHO -------------------------------------
ECHO ======PRESS ANY KEY TO CONTINUE======
PAUSE > NUL
GOTO MENU
:Selection2
Call cleanup.bat
:Selection3
and in here too...
:Selection4
and so on
:Selection5
and so on
:Selection6
and so on
:Selection7
and so on
:Selection8
and so on
:Selection9
and so on
:Quit
CLS
ECHO ==============THANKYOU===============
ECHO -------------------------------------
ECHO ======PRESS ANY KEY TO CONTINUE======
PAUSE>NUL
EXIT
pause
cls
) else (
goto top
)
goto top
How to make the program accept more than 1 command?
For example 1,3,5 to execute in the same time?
or another question, how its possible to undo .exe back to .bat?
there such a program?
Suggestion: make call from goto and concatenate the commands with &:
IF /I '%INPUT%'=='1' GOTO:Selection1
IF /I '%INPUT%'=='2' CALL:Selection2&CALL:Selection2&CALL:Selection4
IF /I '%INPUT%'=='3' CALL:Selection3&CALL:Selection3
IF /I '%INPUT%'=='4' CALL:Selection4&CALL:Selection4
IF /I '%INPUT%'=='5' CALL:Selection5
IF /I '%INPUT%'=='6' CALL:Selection6
IF /I '%INPUT%'=='7' CALL:Selection7
IF /I '%INPUT%'=='8' CALL:Selection8
IF /I '%INPUT%'=='9' CALL:Selection9
IF /I '%INPUT%'=='Q' GOTO:Quit
To get this work you must alse add goto:eof (eof=end of file) after the jump labels, eg.:
:Selection2
Call cleanup.bat
goto:eof
:Selection3
and in here too...
goto:eof
:Selection4
and so on
goto:eof
:Selection5
and so on
goto:eof
...
..
.
goto:eof returns control to the main program.
Is this what you were looking for?
File Menu.cmd
#echo off
setlocal
set quit=false
set /p InputChoices=Enter Choice(s) (A,B,C)
echo %InputChoices%
call :executeChoices %InputChoices%
endlocal
goto :eof
:executeChoices
if [%1]==[] goto :eof
call :Step%1
shift
goto :executeChoices
goto :eof
:StepA
echo Step A
goto :eof
:StepB
echo Step B
goto :eof
:StepC
echo Step C
goto :eof
Works like this:
c:\>Menu.cmd
Enter Choice(s) (A,B,C) b c a
b c a
Step B
Step C
Step A
You can use the start "" command keyword and each command will run in it's own window, but initiated by your menu batch file.

Resources