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.
Related
For my AP Physics 2 project we have to create something that can calculate the equations for resistors and capacitors, I'm having problems with having the variables actually add up to a complete number rather than just being 2+4+4 as an output.
Below is my code so far:
#echo off
echo Do you want Resitors, or Capacitors.
echo Type R or C when prompted.
set /p input0=Enter:
if %input0% equ R goto R1
if %input0% equ C goto C1
goto startup
echo Press any key to continue.
pause>nul
:R1
cls
echo Do you want Series or Parallel?
echo Type S or P when prompted.
set /p input1=Enter:
if %input1% equ S goto S1
if %input1% equ P goto P1
goto Startup
echo Press any key to continue.
pause>nul
:S1
cls
echo What are your 3 values?
set /p input2=Enter:
echo.
set /p input3=Enter:
echo.
set /p input4=Enter:
echo.
set /p "Answer=%input2%+%input3%+%input4%"
echo %Answer%
goto Startup
echo Press any key to continue.
pause>nul
:P1
cls
echo What are your 3 values?
set /p input5=Enter:
echo.
set /p input6=Enter:
echo.
set /p input7=Enter:
echo.
set /a "Answer=(1/((1/%input6%)+(1/%input5%)+(1/%input7%)))"
echo %Answer%
goto Startup
echo Press any key to continue.
pause>nul
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 =
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)
I made a chat program and I want it to auto refresh so i can get rid of the refresh option I have on it. the only problem is I would need to have everything from :A all to way to Echo -----.... to repeat itself while everything below does not. And I do not want it to be split into 2 files.
:A
cls
Echo Server: %S%
Echo Press Q to Quit Or Press R to refresh chat log.
echo ---------------------------------------------------------
type %S%.txt
echo ---------------------------------------------------------
set /p M=Enter Your Message:
if "%M%"=="Q" goto B
if "%M%"=="q" goto B
if "%M%"=="R" goto A
if "%M%"=="r" goto A
echo %U%: %M% >>%S%.txt
goto A
Note
if /I Do a case Insensitive string comparison;
:eof This predefined label will exit the current routine;
call :label Jump to a label (subroutine) in the current batch script.
Next code snippet could help.
:A
call :repeatHeader
set /p "M=Enter Your Message: "
if /I "%M%"=="Q" goto :B
if /I "%M%"=="R" (
call :refreshLog
goto :A
)
echo %U%: %M% >>%S%.txt
goto :A
:repeatHeader
Echo Server: %S%
Echo Press Q to Quit Or Press R to refresh chat log.
goto :eof
:refreshLog
cls
echo ---------------------------------------------------------
type %S%.txt
echo ---------------------------------------------------------
goto :eof
:B
I'm trying to make a Batch file that will increment a variable by 1 each time it loops, and then check if the variable is equal to 5, and if it isn't, it loops again. I know there's probably a while loop for this, but I didn't know how to do that, and I'm just enjoying learning Batch for fun right now
Here's the code, it doesn't work the way it should, it just displays a 0: and then does nothing else. So how would I go about fixing it? I have a feeling I'm setting and incrementing the variable wrong, and maybe it's confused about the 2 if statements? (Does it have an else if....?) Anyways, thanks for the help
#echo off
set /p i=0:
goto A
:A
set /p i=i+1:
if i != 5 goto C
if i == 5 goto B
:C
echo Test :D
:B
pause>nul
Note: I don't know a lot of Batch and I'm not a pro, but I like to learn and I'm just doing this for future reference, and because I enjoy it. So, this code probably isn't good, but I want to know how I can accomplish this.
This is a way to simulate the while loop you are trying to accomplish. Only one goto is needed:
#echo off
set /a x=0
:while
if %x% lss 5 (
echo %x%
pause>nul
set /a x+=1
goto :while
)
echo Test :D
You can do that with a simple FOR command :
for /l %%x in (0,1,100) do (
echo %%x
)
You can replace 100 by the number you want
To set a numerical value to a variable, you may use the /a switch:
The /A switch specifies that the string to the right of the equal sign
is a numerical expression that is evaluated.
(Type SET /? for all the help).
Second, check your goto flow - this never loops back to A.
Third, check the syntax of the if expression (!= doesn't exist in batch).
This should work:
#echo off
set var1=0
:loop
set /a var1=%var1%+1
echo %var1%
if %var1% EQU 5 (
goto :end
) else (
goto :loop
)
:end
pause
#echo off
set a=0
:Count
set /a a=a+1
echo %a%
goto Count
try this:
#if (#CodeSection == #Batch) #then
#echo off
:a
cls
color c
echo --------------
echo start:
echo --------------
set /p start=
cls
echo --------------
echo start: %start%
echo --------------
echo --------------
echo stop:
echo --------------
set /p stop=
cls
echo --------------
echo start: %start%
echo --------------
echo --------------
echo stop: %stop%
echo --------------
echo.
echo.
echo Start in:
timeout /t 2 /nobreak >nul
echo. 5
timeout /t 1 /nobreak >nul
echo. 4
timeout /t 1 /nobreak >nul
echo. 3
timeout /t 1 /nobreak >nul
echo. 2
timeout /t 1 /nobreak >nul
echo. 1
timeout /t 1 /nobreak >nul
cls
echo --------------
echo start: %start%
echo --------------
echo --------------
echo stop: %stop%
echo --------------
echo.
echo.
echo.
echo ============================================
set SendKeys=CScript //nologo //E:JScript "%~F0"
%SendKeys% ">----"
%SendKeys% "{enter}"
:while
echo %start%
%SendKeys% "%start%"
%SendKeys% "{enter}"
set /a start=start+1
timeout /t 1 /nobreak >nul
if %start% leq %stop% goto :while
goto :end
:end
echo ============================================
%SendKeys% ">----"
%SendKeys% "{enter}"
:c
echo count again? Y/N
set /p return=
if %return% == Y goto :a
if %return% == N goto :b
goto :c
:b
#end
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));