Windows 如何简化cmd终端中的重复命令?

Windows 如何简化cmd终端中的重复命令?,windows,performance,batch-file,Windows,Performance,Batch File,我写了许多重复的命令行,比如下面的一行,也许有其他人的输入来简化命令?尽可能简单 @echo off :stro cls echo. echo Enter you term: echo ++++++++++++++++++++++ echo 1) Command Prompt (CMD) echo 2) Power Shell echo 3) Exit echo. set /p kod= if %kod% == 1 goto cmde if %kod% ==

我写了许多重复的命令行,比如下面的一行,也许有其他人的输入来简化命令?尽可能简单

@echo off
:stro
cls
echo. 
echo    Enter you term:
echo    ++++++++++++++++++++++
echo    1) Command Prompt (CMD)
echo    2) Power Shell
echo    3) Exit
echo.   
set /p kod=
if %kod% == 1 goto cmde
if %kod% == 2 goto pwsl
if %kod% == 3 goto exitx  
:exitx
echo set speech = Wscript.CreateObject("SAPI.spVoice") >> "tuntu.vbs"
echo speech.speak "thank you for use me. i hope you have a nice day. bye bye" >> "tuntu.vbs"
attrib +h "tuntu.vbs"
start tuntu.vbs
pause
attrib -h "tuntu.vbs"
del tuntu.vbs
exit
:cmde
start cmd
echo set speech = Wscript.CreateObject("SAPI.spVoice") >> "tuntu.vbs"
echo speech.speak "you choice is number %kod% and you open command prompt CMD"  >> "tuntu.vbs"
attrib +h "tuntu.vbs"
start tuntu.vbs
pause
attrib -h "tuntu.vbs"
del tuntu.vbs
goto stro
:pwsl
start powershell
echo set speech = Wscript.CreateObject("SAPI.spVoice") >> "tuntu.vbs"
echo speech.speak "you choice is number %kod% and you open Power shell"  >> "tuntu.vbs"
attrib +h "tuntu.vbs"
start tuntu.vbs
pause
attrib -h "tuntu.vbs"
del tuntu.vbs
goto stro

然后我想要一个简单的命令行,不包含重复和无聊的句子。感谢您的帮助

仅生成一次
vbs
脚本(使用参数而不是硬编码文本):

然后,您的代码将缩短为:

@echo off

(echo set speech = Wscript.CreateObject("SAPI.spVoice"^)
echo speech.speak WScript.Arguments(0^))>"speak.vbs"
attrib +h speak.vbs
set "say=cscript /nologo speak.vbs"

:stro
cls
echo. 
echo    Enter you term:
echo    ++++++++++++++++++++++
echo    1) Command Prompt (CMD)
echo    2) Power Shell
echo    3) Exit
echo.   

choice /c 123
set kod=%errorlevel%
goto :label%kod%

:label3
%say% "thank you for using me. i hope you have a nice day. bye bye"
exit /b

:label1
start cmd
%say% "your choice is number %kod% and you open command prompt CMD"  
goto stro

:label2
start powershell
%say% "your choice is number %kod% and you open Power shell"
goto stro

我还将您的
set/p
替换为
choice
,因为
choice
处理用户输入并防止无效输入。

很好,但我仍然对上面一行使用
/nologo
感到困惑。哪一行代表什么?在我假设它与所说的声音相关之前,
/nologo
将徽标置于上方(两行
Microsoft(R)Windows脚本主机…
版权(C)Microsoft…
)谢谢你的代码行