问题
Good day!
Recently I made thread, where I asked, how to create, or is it possible to create Tickmenu in Batch.
One of those who answered was - Dennis van Gils, who kindly presented his Multi Select menu.
Here is code:
@echo off
setlocal EnableDelayedExpansion
set "getKeyMacro=powershell -noprofile "^
while (-not (37..40+13).contains($x)) {^
$x = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown').VirtualKeyCode^
}^
if ($x -eq 13) {^
'enter'^
}^
('left','up','right','down')[$x - 37]^
""
set "num=0"
for %%a in ("7zip"
"7zip x64"
"AdobeReader"
"Far x64"
"Far x86") do (
set /A num+=1
set "option!num!=0"
set "option!num!name=%%~a"
)
set "maxOptions=%num%"
set "selected=1"
:select
cls
echo use ^<right^> arrow to continue, ^<up^> and ^<down^> to select, and ^<enter^> to toggle
FOR /L %%G IN (1,1,%maxOptions%) DO (
set "display=[ ]"
if !option%%G! equ 1 set "display=[x]"
if %%G equ !selected! set "display=^>!display!"
echo !display! !option%%Gname!
)
FOR /F "delims==" %%G IN ('%getKeyMacro%') DO set "key=%%G"
if "%key%"=="up" set /a "selected-=1"
if "%key%"=="down" set /a "selected+=1"
if %selected% lss 1 set "selected=1"
if %selected% gtr %maxOptions% set "selected=!%maxOptions%!"
if "%key%"=="enter" goto toggle
if "%key%"=="right" goto OK
goto select
:toggle
set /a "option%selected%+=1"
set /a "option%selected%=!option%selected%!%%2"
goto select
:OK
FOR /L %%G IN (1,1,%maxOptions%) DO (
if !option%%G! equ 1 (
call :logic "%%G"
)
)
pause
goto :eof
:logic
set "install=%~1"
if "%install%"=="1" (
msiexec /i D:\Install\Software\7z920.msi /quiet /qn
echo executing %install%
)
if "%install%"=="2" (
msiexec /i D:\Install\Software\7z920x64.msi /quiet /qn
echo executing %install%
)
if "%install%"=="3" (
Start "" "D:\Install\Software\AdbeRdr11010_en_US"
echo executing %install%
)
if "%install%"=="4" (
msiexec /i "D:\Install\Software\Far x64.msi" /quiet /qn
echo executing %install%
)
if "%install%"=="5" (
msiexec /i "D:\Install\Software\Far x86.msi" /quiet /qn
echo executing %install%
)
When he posted his code, he noted, that at the :logic, I need to create simple If statements so that script can run programs.
I made those If statements but for some reason script still gives me Unexpected error. I am new at Batch scripting so for me, it's to hard to understand this advenced level code.
So, my question is, Why is this code not working?
Regards, Vairis
Edit, Ok guys, I think I will need to Ask Dennis himself, since that's his code ^_^. Thank you everyone for your time. I don't know if this thread should be closed since questions is unanswered, but this question might be at bottom of the page at this moment, so I will ask Moderator to close this Thread.
Once again, Thank you guys :) Regards
回答1:
I will recommand you using a simple menu like this one from DOS Batch - Menus
Description :
This simple menu framework parses itself for batch labels of certain signature and lists them as menu items. The self-parsing feature makes the menu generic. New menu items can be inserted by adding new function blocks without changing the menu infrastructure.
Features:
- simple and well structured
- easy to enhance
- easy to maintain
@echo off
Title Example of a dynamic menu
Mode con cols=70 lines=13 & color 9E
:menuLOOP
echo(
echo( =============================Menu==============================
echo(
for /f "tokens=2* delims=_ " %%A in ('"findstr /b /c:":menu_" "%~f0""') do echo %%A %%B
echo(
echo( ===============================================================
set choice=
echo( & set /p choice=Make a choice or hit ENTER to quit: || GOTO :EOF
echo( & call :menu_[%choice%]
GOTO:menuLOOP
:menu_[1] Install 7zip (x86 bits)
cls
set "Install=Install 7zip (x32 bits)"
rem msiexec /i D:\Install\Software\7z920.msi /quiet /qn
echo Executing %install%
Timeout /T 30 /nobreak>nul
GOTO:menuLOOP
:menu_[2] Install 7zip (x64 bits)
cls
set "Install=Install 7zip (x64 bits)"
rem msiexec /i D:\Install\Software\7z920x64.msi /quiet /qn
echo Executing %install%
Timeout /T 30 /nobreak>nul
GOTO:menuLOOP
:menu_[3] Install Adobe Reader
cls
set "Install=Install Adobe Reader"
rem Start "" "D:\Install\Software\AdbeRdr11010_en_US"
echo Executing %install%
Timeout /T 30 /nobreak>nul
GOTO:menuLOOP
:menu_[4] Far (x64)
cls
set "Install=Install Far (x64)"
Rem msiexec /i "D:\Install\Software\Far x64.msi" /quiet /qn
echo Executing %install%
Timeout /T 30 /nobreak>nul
GOTO:menuLOOP
:menu_[5] Far (x32)
cls
set "Install=Install Far (x32)"
Rem msiexec /i "D:\Install\Software\Far x86.msi" /quiet /qn
echo Executing %install%
Timeout /T 30 /nobreak>nul
GOTO:menuLOOP
来源:https://stackoverflow.com/questions/38651627/multi-select-menu