我如何让人们在批处理文件中选择

时间:2017-08-24 11:41:45

标签: batch-file

我已经知道如何让人们从0到9中选择,但我需要更多选择 你们有什么想法吗? 我已经尝试过添加更多的数字,比如10或11,但它只选择第一个数字,所以10 = 1和11 = 1等等。
我需要这个固定的,因为我有更多的选择,子目录看起来非常糟糕 我到处搜寻。

这是可以从0到9的代码(我知道它不是初学者)

.xlsx

2 个答案:

答案 0 :(得分:0)

这是否像你想要的那样工作?

@Echo Off

:StartNet
ClS
Echo.
Echo Net...

Echo  0. Accounts
Echo  1. Computer
Echo  2. Config
Echo  3. Continue
Echo  4. File
Echo  5. Group
Echo  6. Help
Echo  7. Helpmsg
Echo  8. Localgroup
Echo  9. Pause
Echo 10. Session
Echo 11. Share
Echo 12. Start
Echo 13. Statistics
Echo 14. Stop
Echo 15. Time
Echo 16. Use
Echo 17. User
Echo 18. View

Set/P "selection="

GoTo %selection% 2>Nul

Echo.
"%choice%" is not an option
Timeout 3 /NoBreak>Nul
GoTo StartNet

:0
ClS
Echo Wait...
Net Accounts
Timeout -1
Exit/B

:1
ClS
Echo Wait...
Net Computer
Timeout -1
Exit/B

:2
ClS
Echo Wait...
Net Config
Timeout -1
Exit/B

:3
ClS
Echo Wait...
Net Continue
Timeout -1
Exit/B

:4
ClS
Echo Wait...
Net File
Timeout -1
Exit/B

:5
ClS
Echo Wait...
Net Group
Timeout -1
Exit/B

:6
ClS
Echo Wait...
Net Help
Timeout -1
Exit/B

:7
ClS
Echo Wait...
Net Helpmsg
Timeout -1
Exit/B

:8
ClS
Echo Wait...
Net Localgroup
Timeout -1
Exit/B

:9
ClS
Echo Wait...
Net Pause
Timeout -1
Exit/B

:10
ClS
Echo Wait...
Net Session
Timeout -1
Exit/B

:11
ClS
Echo Wait...
Net Share
Timeout -1
Exit/B

:12
ClS
Echo Wait...
Net Start
Timeout -1
Exit/B

:13
ClS
Echo Wait...
Net Statistics
Timeout -1
Exit/B

:14
ClS
Echo Wait...
Net Stop
Timeout -1
Exit/B

:15
ClS
Echo Wait...
Net Time
Timeout -1
Exit/B

:16
ClS
Echo Wait...
Net Use
Timeout -1
Exit/B

:17
ClS
Echo Wait...
Net User
Timeout -1
Exit/B

:18
ClS
Echo Wait...
Net View
Timeout -1
Exit/B

答案 1 :(得分:-1)

CHOICE 命令,这也是choice不如环境变量名称的原因。在命令提示符窗口choice /?中运行以获取有关此命令的帮助。它的优点是可以安全地防止用户输入错误信息。

@echo off
goto StartNet

:NextRun
echo/
pause

:StartNet
cls
echo/
echo Net ...
echo/
echo   A ... Accounts
echo   B ... Computer
echo   C ... Config
echo   D ... Continue
echo   E ... File
echo   F ... Group
echo   G ... Help
echo   H ... Helpmsg
echo   I ... Localgroup
echo   J ... Pause
echo   K ... Session
echo   L ... Share
echo   M ... Start
echo   N ... Statistics
echo   O ... Stop
echo   P ... Time
echo   Q ... Use
echo   R ... User
echo   S ... View
echo/
echo   X ... Exit
echo/
%SystemRoot%\System32\choice.exe /C ABCDEFGHIJKLMNOPQRSX /N /M "Your choice: "
if errorlevel 20 exit /B
cls
echo Wait ...
echo/
goto Option%ERRORLEVEL%

:Option1
%SystemRoot%\System32\net.exe Accounts & goto NextRun
:Option2
%SystemRoot%\System32\net.exe Computer & goto NextRun
:Option3
%SystemRoot%\System32\net.exe Config & goto NextRun
:Option4
%SystemRoot%\System32\net.exe Continue & goto NextRun
:Option5
%SystemRoot%\System32\net.exe File & goto NextRun
:Option6
%SystemRoot%\System32\net.exe Group & goto NextRun
:Option7
%SystemRoot%\System32\net.exe Help & goto NextRun
:Option8
%SystemRoot%\System32\net.exe Helpmsg & goto NextRun
:Option9
%SystemRoot%\System32\net.exe Localgroup & goto NextRun
:Option10
%SystemRoot%\System32\net.exe Pause & goto NextRun
:Option11
%SystemRoot%\System32\net.exe Session & goto NextRun
:Option12
%SystemRoot%\System32\net.exe Share & goto NextRun
:Option13
%SystemRoot%\System32\net.exe Start & goto NextRun
:Option14
%SystemRoot%\System32\net.exe Statistics & goto NextRun
:Option15
%SystemRoot%\System32\net.exe Stop & goto NextRun
:Option16
%SystemRoot%\System32\net.exe Time & goto NextRun
:Option17
%SystemRoot%\System32\net.exe Use & goto NextRun
:Option18
%SystemRoot%\System32\net.exe User & goto NextRun
:Option19
%SystemRoot%\System32\net.exe View & goto NextRun

另请参阅Batch file choice loop on unexpected input上的回答,其中包含使用echo/代替echo.的原因以及 CHOICE errorlevel持有退出/返回上一个命令/可执行文件的代码。