Multiple selection menus in a batch file?

Hi, I want to create a batch menu that asks: "Select the application you want to install?" eg

  1. App1
  2. App2
  3. App3
  4. App4
  5. app5
  6. All applications

Choose which application: _

For example, I need to install App2, App3, and App5 so that I can print by the application identifier "Select an application: 2,3,5." And when the user selects option 6, he will install all the applications!

I know this is possible for Bash scripts, but am I not sure about batch scripts?

An example of a batch menu is http://mintywhite.com/software-reviews/productivity-software/create-multiple-choice-menu-batchfile/

+6
source share
13 answers

Answer

, . , . , , , script.

Script

:: Hide Command and Set Scope
@echo off
setlocal EnableExtensions

:: Customize Window
title My Menu

:: Menu Options
:: Specify as many as you want, but they must be sequential from 1 with no gaps
:: Step 1. List the Application Names
set "App[1]=One"
set "App[2]=Two"
set "App[3]=Three"
set "App[4]=Four"
set "App[5]=Five"
set "App[6]=All Apps"

:: Display the Menu
set "Message="
:Menu
cls
echo.%Message%
echo.
echo.  Menu Title
echo.
set "x=0"
:MenuLoop
set /a "x+=1"
if defined App[%x%] (
    call echo   %x%. %%App[%x%]%%
    goto MenuLoop
)
echo.

:: Prompt User for Choice
:Prompt
set "Input="
set /p "Input=Select what app:"

:: Validate Input [Remove Special Characters]
if not defined Input goto Prompt
set "Input=%Input:"=%"
set "Input=%Input:^=%"
set "Input=%Input:<=%"
set "Input=%Input:>=%"
set "Input=%Input:&=%"
set "Input=%Input:|=%"
set "Input=%Input:(=%"
set "Input=%Input:)=%"
:: Equals are not allowed in variable names
set "Input=%Input:^==%"
call :Validate %Input%

:: Process Input
call :Process %Input%
goto End


:Validate
set "Next=%2"
if not defined App[%1] (
    set "Message=Invalid Input: %1"
    goto Menu
)
if defined Next shift & goto Validate
goto :eof


:Process
set "Next=%2"
call set "App=%%App[%1]%%"

:: Run Installations
:: Specify all of the installations for each app.
:: Step 2. Match on the application names and perform the installation for each
if "%App%" EQU "One" echo Run Install for App One here
if "%App%" EQU "Two" echo Run Install for App Two here
if "%App%" EQU "Three" echo Run Install for App Three here
if "%App%" EQU "Four" echo Run Install for App Four here
if "%App%" EQU "Five" echo Run Install for App Five here
if "%App%" EQU "All Apps" (
    echo Run Install for All Apps here
)

:: Prevent the command from being processed twice if listed twice.
set "App[%1]="
if defined Next shift & goto Process
goto :eof


:End
endlocal
pause >nul
+6
+5

set /p :

echo What would you like to install?
echo 1 - App1
echo 2 - App2

set /p whatapp=

if %whatapp%==1 (
    codetoinstallapp1
) else if %whatapp%==2 (
    codetoinstallapp2
) else (
    echo invalid choice
)
+3
@echo off
:menu
cls
echo.
echo Select the case color you want to create:
echo ==========================================
echo.
echo App 1
echo App 2
echo App 3
echo App 4
echo.
echo ==========================================
echo Please answer Y/N to the following:

set /p App1= Install App 1?
set /p App2= Install App 2?
set /p App3= Install App 3?
set /p App4= Install App 4?

if /I "%App1%" EQU "Y" goto :Option-1
if /I "%App1%" EQU "N" goto :1
:1
if /I "%App2%" EQU "Y" goto :Option-2
if /I "%App2%" EQU "N" goto :2
:2
if /I "%App3%" EQU "Y" goto :Option-3
if /I "%App3%" EQU "N" goto :3
:3
if /I "%App4%" EQU "Y" goto :Option-4
if /I "%App4%" EQU "N" goto :End



:Option-1
App 1 Loc.
goto 1
:Option-2
App 2 Loc.
goto 2
:Option-3
App 3 Loc.
goto 2
:Option-4
App 4 Loc.
:End

Exit
+2

, :

echo.1) first choice
echo.2) second choice
echo.3) third choice
echo.4) fourth choice

:: the choice command

set pass=
choice /c 1234 /n /m "Choose a task"
set pass=%errorlevel%

::the choices

if errorlevel 1 set goto=1
if errorlevel 2 set goto=2
if errorlevel 3 set goto=3
if errorlevel 4 set goto=4
goto %goto%

1-4, .

+1

. :

echo whateveryouwant

, .

: ?

- , - ; move .

0

script , :

@echo off
setlocal
:begin
cls
echo [LOCAL ACCOUNTS REMOTE ADMIN] --------------------------------------
echo   1 -- List local accounts on a remote machine
echo   2 -- Create a local account on a remote machine
echo   3 -- Change a local account password on a remote machine
echo   4 -- Delete a local account on a remote machine
echo;
echo   5 -- exit
echo;
set /P rmFunc="Enter a choice: "
echo --------------------------------------------------------------------
for %%I in (1 2 3 4 5 x) do if #%rmFunc%==#%%I goto run%%I
goto begin

:run1
rem list local accounts code
goto begin

:run2
rem create local account code
goto begin

rem and so on, until...

:run5
:run9
:run99
:runx
endlocal
goto :EOF

set /p for...in. for...in , , , goto run#; .

0

, / . , , - , ( ).

, ( , - , , ).

@echo off & setlocal enabledelayedexpansion

echo What would you like to install?
::Put your options here, preferably numbered.
set /p op=Type the numbers of the software you want to install (separated by commas with no spaces. E.g: 1,3,2): 

for /f "delims=, tokens=1-5" %%i in ("op") do (
set i=%%i
set j=%%j
set k=%%k
set l=%%l
set m=%%m
)
if %i%X neq X set last=1b & goto %i%
:1b
if %j%X neq X set last=2b & goto %j%
:2b
if %k%X neq X set last=3b & goto %k%
:3b
if %l%X neq X set last=4b & goto %l%
:4b
if %m%X neq X set last=%m% & goto %m%
goto next

:1
::Put the code for doing the first option here
goto %last%
:2
::Put the code for doing the second option here
goto %last%
:3
::Put the code for doing the third option here
goto %last%
:4
::Put the code for doing the fourth option here
goto %last%
:5
::Put the code for doing the fifth option here
goto %last%

: :: -...

. ..

- (, "1,3,4" ), , , , , , , . , .

0

, "Validate Input" :

, "^ & <". , .

set "Input=%Input:"=%"
set "Input=%Input:^^=%"
set "Input=%Input:>=%"
set "Input=%Input:<=%"
set "Input=%Input:^&=%"
set "Input=%Input:|=%"
set "Input=%Input:(=%"
set "Input=%Input:)=%"
:: Equals are not allowed in variable names
set "Input=%Input:^==%"

^ , - "<" " > " ( ). , , "<" , " > " .

, "<" , , ")" !!

set "Input=%Input:"=%"
set "Input=%Input:^^=%"
set "Input=%Input:>=%"
set "Input=%Input:^&=%"
set "Input=%Input:|=%"
set "Input=%Input:(=%"
set "Input=%Input:)=%"
set "Input=%Input:<=%"
:: Equals are not allowed in variable names
set "Input=%Input:^==%"

.

0

@echo off
:a
echo Welcome to a casual log-in (you are a idiot)

echo.

pause


echo ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ

set /p c=Email:

echo ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ

set /p u=Password:

echo ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ

msg * Welcome %c%.

goto a
0

.

@echo off

:preset
 set st5=V


:loop
cls

::#menu#
echo.
echo name_1: [%st3%]
echo.
echo name_2: [%st4%]
echo.
echo name_3: [%st5%]
echo.
echo.
echo [q] EXIT  
echo.
echo [i] INSTALL
echo.
::#menu#

choice /C qi123 /N /M "Select [1-9] >> [i]nstall or [q]uit:"
echo.
:: beware: [q]->%errorlevel%=1; [3]->%errorlevel%=5;


::## check begin ##
set inp=%errorlevel%
if %inp%==1 (exit)
if %inp%==2 (call :apply)
::switch
if defined st%inp% (
 set st%inp%=
  ) else (
 set st%inp%=X
)
goto :loop
::## check end ##

 :apply
for /L %%i in (3,1,5) do (
if defined st%%i call :st%%i
)
pause
goto :loop



:st3
echo First Command
echo.
goto :eof

:st4
echo Second Command
echo.
goto :eof

:st5
echo Third Command
echo.
goto :eof

, : preset.

0

.

@echo off
echo Which app do you want to install?
echo [APP 1]
echo [APP 2]
echo [APP 3]
echo.
echo Type 1, 2, or 3.
set /p "AppInstaller=>"
if %AppInstaller%==1 goto 1
if %AppInstaller%==2 goto 2
if %AppInstaller%==3 goto 3
:1
[INSTALL CODE]
:2
[INSTALL CODE]
:3
[INSTALL CODE]

A menu encoded this way will look like this:

Which app do you want to install?
[APP 1]
[APP 2]
[APP 3]

Type 1, 2, or 3.
>_

The code sets the AppInstaller variable to 1, 2, or 3. The file determines this and redirects you to the installer for each of them.

0
source

This is a pretty simple code that I use in multi-choice games:

@echo off
color 0a
cls
:download
echo App 1
echo App 2
echo App 3
echo App 4
echo App 5
echo All Apps
echo 
echo Select What App (1, 2, 3, ect.):
set /p apps=

if %apps%==1 goto 1
if %apps%==1 goto 2
if %apps%==1 goto 3
if %apps%==1 goto 4
if %apps%==1 goto 5
if %apps%==1 goto all

:1
(Your Code Here)
:2
(Your Code Here)
:3
(Your Code Here)
:4
(Your Code Here)
:5
(Your Code Here)
:all
(Your Code Here)
0
source

All Articles