【问题标题】:Is there any possible way to create Tick menu for Batch file有没有办法为批处理文件创建勾选菜单
【发布时间】:2016-07-22 08:15:08
【问题描述】:

我必须制作批处理文件,它在运行时会给我运行安装文件的选项。我需要让它成为多选菜单。

我做了一些研究并找到了代码,即多项选择菜单,它要求用户输入。忘记链接了,抱歉。

但这是我的问题。我希望菜单有复选框(勾选框),勾选后安装这些程序。

有没有关于如何做的教程?或者,如果可能的话?

【问题讨论】:

  • 这会比较难。但是你可以嵌入mshta/html弹出窗口。查看示例here来学习技术。在html中创建选择菜单很容易,你只需要决定你将如何解析数据。

标签: batch-file


【解决方案1】:

它不可点击,但这可能是你想要的:

@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 ("Install thing 1"
            "Do thing 2"
            "Execute thing 3"
            "Run thing 4"
            "Test thing 5") 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"
echo executing %install%

将安装逻辑放在echo executing %install%所在的位置,例如if "%install%"=="1" start "" "somefileToInstall"

【讨论】:

  • 谢谢!这几乎是理想的。您为我节省了几天创建此菜单的时间。 :)
【解决方案2】:

DOS Batch - Menus是一个很好的教程,你可以创建一个高级的动态菜单

这些是我从中学到的一些示例,以便轻松创建这样的菜单:

Sound in batch?

How to check and correct user input when he omit the extension .exe to kill the process?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-10
    • 2014-03-28
    • 2017-10-01
    相关资源
    最近更新 更多