【发布时间】:2018-01-11 14:21:35
【问题描述】:
我有 16 个不同的 powershell 脚本来安装应用程序。如何创建单个批处理文件来要求用户输入以选择要运行的 powershell 脚本?
例子:
我只想安装一个应用程序,所以批处理脚本会要求输入,我将输入visualstudio。然后它将运行适当的 powershell 脚本来安装 Visual Studio。
SetLocal
@echo on
:menu
CHOICE /C VCNE /M "[V]isualStudio, [N]otePad, [c]hrome, [E]xit"
set answer=%CHOICE%
if /i "%answer:~,1%" EQU "V" goto visualstudio
if /i "%answer:~,1%" EQU "C" goto chrome
if /i "%answer:~,1%" EQU "N" goto notepad
if /i "%answer:~,1%" EQU "E" goto Exit
:chrome
C:
cd\
cd PowerShell
powershell -file Chrome.ps1
goto Menu
:visualstudio
C:
cd\
cd PowerShell
powershell -file visualstudio.ps1
goto Menu
:notepad
C:
cd\
cd PowerShell
powershell -file visualstudio.ps1
goto Menu
:Exit
exit
【问题讨论】:
-
在提示符下输入
choice /?,这将为您提供您所需要的所有灵活性 - 以及所有单键。 -
感谢您的评论。尝试了相同的方法,但无论输入是什么,它都会转到 :chrome,
-
尝试将修改后的代码编辑到您的问题中,以便我们可以看到并可能修复您正在使用的内容。
-
因为
answer是空的,所以陷入:chrome套路;%CHOICE%来自哪里?您是否阅读了在命令提示符窗口中键入choice /?时出现的choice命令的帮助?
标签: batch-file