批处理文件上的多项选择菜单?

2024-03-31

您好,我想制作一个批处理文件菜单,询问“选择您要安装的应用程序?”例如

  1. App1
  2. App2
  3. App3
  4. App4
  5. App5
  6. ALL Apps

选择什么应用程序:_

我想要的是,例如我想安装 App2、App3 和 App5,这样我就可以通过 App ID 的 'Select what app:2,3,5' 进行输入。当用户选择选项 6 时,它将安装所有应用程序!

我知道这在 bash 脚本中是可能的,但我不确定批处理脚本吗?

批处理菜单的一个示例是http://mintywhite.com/software-reviews/productivity-software/create-multiple-choice-menu-batchfile/ http://mintywhite.com/software-reviews/productivity-software/create-multiple-choice-menu-batchfile/


Answer

这将做你想做的事。如果您有任何疑问,请告诉我。您所要做的就是按照脚本中列出的两个步骤进行操作。

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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

批处理文件上的多项选择菜单? 的相关文章

随机推荐

  • SQL Server SP - 传递“IN”数组列表的参数?

    有没有办法将值数组作为 SQL Server 2005 的单个参数传递到 SP 的 IN 部分 例如 从 MyTable 中选择 其中 ID IN MyValueArray 在 2005 年及更早版本中 您无法将数组作为参数传递给存储过程
  • 如何强制兼容性视图

    我安装了 IE 11 但我还需要在 IE 8 9 和 10 中运行一些测试 运行测试时如何强制兼容模式 仅供参考 我确实尝试了 F12 并将模式设置为 8 它可以手动工作 但不能通过 selenium 工作 谢谢 我最近遇到了完全相同的问题
  • 使用 uncurry 函数进行特定类型推断

    我一直在玩uncurry在 GHCi 中运行函数 我发现了一些我根本无法理解的东西 当我申请时uncurry to the 函数并将其绑定到某个变量 如下面的代码所示 编译器推断其类型特定于Integer Prelude gt let ad
  • Angularjs ui-router 奇怪的行为与路由中的附加段

    当我向路线添加错误的段时 我遇到了 ui router 问题 一个例子 http xxx xxxxx xxx 角色 http xxx xxxxx xxx roles工作正常 这是一个不带参数定义的路由 但是如果我在浏览中添加另一个片段htt
  • 引起原因:java.lang.IllegalArgumentException:provider=network

    试图找到我的设备的当前位置 代码在这里 package com example location import android app Activity import android content Context import andro
  • 针对服务器端应用程序使用 Google SignIn 进行增量组合授权

    登录时使用服务器端流程 https developers google com identity sign in web server side flow 或请求额外范围的授权 auth2 grantOfflineAccess 结果访问 刷
  • 是否可以在扩展 AppWidgetProvider 的 Widget 中使用 TextView Marquee?

    我对Android编程很陌生 我到处都读过 但似乎找不到任何解决方案 基本问题是我在小部件中有一个 TextView 并且我希望当文本长于 TextView 布局宽度时文本滚动 这是我在layout widget xml 中的代码
  • 由于过滤器处于错误状态,因此无法执行操作 GetCurrentBuffer

    由于过滤器处于错误状态 因此无法执行该操作 我在尝试运行 hr m pGrabber gt GetCurrentBuffer cbBuffer NULL 时收到此错误 奇怪的是 它最初在我停止图表时工作 现在在运行或停止图表时失败 那么 它
  • 将 Bitrise 配置文件存储在 git 存储库中

    有没有办法将我的应用程序的配置文件与代码一起存储在我的 git 存储库中 并使 Bitrise 在运行时安装它们 这无需手动将配置文件上传到 Bitrise 这只是复制的问题 mobileprovision文件到正确的用户路径 cp Pro
  • 空的樱桃挑选消息中的“可能由于冲突解决”意味着什么?

    当您尝试挑选当前分支中已有的提交时 会出现以下消息 The previous cherry pick is now empty possibly due to conflict resolution 将显示 这句话的意思很清楚 然而 该消息
  • 验证消息安全性时发生错误 - SAML 令牌

    几年前 我们开发了一个客户端来消费usi ws v2 https 3pt portal usi gov au Service v2 UsiService wsdl 这个网络服务使用STS服务v2 https thirdparty authe
  • 从 ASP.NET 获取 Windows 计划任务中任务的上次运行日期

    是否可以从 ASP NET 获取 Windows 计划任务中计划任务的上次运行日期 理想情况下 最好能够列出 启动和停止这些任务 尽管在这个阶段 我想做的主要事情是检索特定计划任务的上次运行时间 如果这是不可能的 我的解决方法是简单地让正在
  • 为什么时间戳的限制是2038?

    我刚刚在运行日历脚本时发现 PHP 中的时间戳限制为 2038 这到底意味着什么 为什么是2038年而不是2050年或2039年 如果时间戳只计算给定日期 1970 年 的秒数 为什么要进行限制 该限制是由大多数 C 库用于表示该计数的 4
  • 在 emacs24 中加载颜色主题时如何修复“Symbol 的函数定义无效”?

    当我加载我的 emacs 虽然颜色主题暮光加载得很好 但它向我显示了以下错误消息 Symbol s function definition is void color theme twilight In my emacs我添加了以下几行来添
  • Bash 脚本查找文件中每个字母的频率

    我试图找出输入文件中英文字母表中每个字母的出现频率 我怎样才能在 bash 脚本中做到这一点 我的解决方案使用grep sort and uniq grep o file sort uniq c 忽略大小写 grep o file sort
  • Robot Framework - Selenium2Library - IE11 完成测试非常不稳定

    基本上 如果测试用例在 Chrome FF 或 Edge 上运行 它们就不会出现问题 您甚至可以在测试后使用浏览器 然而 对于 IE 从网络驱动程序运行它基本上会使浏览器不稳定 这适用于框架和手动使用 我遇到的问题是某些元素在被选择时会闪烁
  • PHP DOMDocument:解析未转义字符串时出错

    我在使用 PHP 解析 HTML 时遇到问题DOM文档 我正在解析的 HMTL 有以下内容脚本标签 这段代码有两个问题 1 里面的HTMLbuttonWi
  • 如何在运行时更改软键盘的高度?

    我正在设计一个软键盘 当用户在横向和纵向模式之间进行选择时 我想在运行时更改其高度 我知道如何更改 xml 中键的高度 但我需要动态执行此操作 我唯一想到的就是从Keyboard并覆盖它的设置按键高度 int height 但它似乎毫无用处
  • 在 Axios 中自定义日期序列化

    默认情况下 当 JavaScript 对象包含 Date 对象时 Axios 将其序列化为 UTC 这意味着传输的时间是使用时区进行转换的 这不适用于我的用例 我需要将没有时区转换的时间发送为 UTC 我实现了一个基于的自定义序列化器 15
  • 批处理文件上的多项选择菜单?

    您好 我想制作一个批处理文件菜单 询问 选择您要安装的应用程序 例如 App1 App2 App3 App4 App5 ALL Apps 选择什么应用程序 我想要的是 例如我想安装 App2 App3 和 App5 这样我就可以通过 App