问题描述
最近我在询问线程的地方创建了线程,如何创建它,或者可以批量创建Tickmenu.
Recently I made thread, where I asked, how to create, or is it possible to create Tickmenu in Batch.
其中一个回答的人是- Dennis van Gils ,他提出了多选"菜单.
One of those who answered was - Dennis van Gils, who kindly presented his Multi Select menu.
这是代码:
@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%
)
他在发布代码时指出,在:logic上,我需要创建简单的If语句,以便脚本可以运行程序.
When he posted his code, he noted, that at the :logic, I need to create simple If statements so that script can run programs.
我做了那些If语句,但是由于某种原因,脚本仍然给我意外错误.我是Batch脚本的新手,所以对我来说,很难理解此高级代码.
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?
关于,瓦里斯
再一次,谢谢大家:)问候
Once again, Thank you guys :)Regards
推荐答案
我将通过 DOS批处理-菜单
I will recommand you using a simple menu like this one from DOS Batch - Menus
说明:
这个简单的菜单框架解析自身以获取某些签名的批处理标签,并将其列为菜单项.自解析功能使菜单通用.可以通过添加新功能块来插入新菜单项,而无需更改菜单基础结构.
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.
功能:
- 结构简单
- 易于增强
- 易于维护
@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
这篇关于多选菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!