Board logo

标题: [系统相关] [已解决]批处理菜单10秒内作出选择,否则自动退出该怎么设计 [打印本页]

作者: thp2008    时间: 2022-10-18 21:13     标题: [已解决]批处理菜单10秒内作出选择,否则自动退出该怎么设计

本帖最后由 thp2008 于 2022-10-22 11:25 编辑

我想在批处理中间,加个菜单,让用户10秒内作出选择,如果不选择,则等待10秒后自动退出。10秒内选择,则跳转。
  1. echo.
  2. echo    请选择你想切换的宽带链路,10秒钟,未选择,将自动退出。
  3. echo.
  4. echo    A、更改上网链路为- (中国电信)
  5. echo.
  6. echo    B、更改上网链路为- (中国移动)
  7. echo.
  8. echo    C、更改上网链路为- (中国联通)
  9. echo.
  10. echo    D、更改上网链路为- (天威宽带)
  11. echo.
  12. echo.
  13. set choice=
  14. choice /c abcd /M     请输入选择的字母,不区分大小写,不需要回车:
  15. IF NOT "%Choice%"=="" SET Choice=%Choice:~0,1%
  16. if errorlevel 4 goto TianWei
  17. if errorlevel 3 goto LianTong
  18. if errorlevel 2 goto YiDong
  19. if errorlevel 1 goto DianXing
  20. :TianWei
  21. :LianTong
  22. :YiDong
  23. :DianXing
  24. :end
  25. exit
复制代码
不知道该如何改动,组合。
  1. TIMEOUT /T 10 /NOBREAK
复制代码
感谢!
作者: lancer    时间: 2022-10-19 09:04

choice是可以设置默认选项的,在指定时间以后,默认选择,你看看choice的帮助文件
作者: holley    时间: 2022-10-19 11:23

本帖最后由 holley 于 2022-10-19 11:28 编辑

回复 1# thp2008
这种?
  1. @echo off
  2. echo.
  3. echo    请选择你想切换的宽带链路,10秒钟,未选择,将自动退出。
  4. echo.
  5. echo    A、更改上网链路为- (中国电信)
  6. echo.
  7. echo    B、更改上网链路为- (中国移动)
  8. echo.
  9. echo    C、更改上网链路为- (中国联通)
  10. echo.
  11. echo    D、更改上网链路为- (天威宽带)
  12. echo.
  13. echo    E、退出
  14. echo.
  15. echo.
  16. set choice=
  17. choice /C "ABCDE" /D "E" /T 10 /M     请输入选择的字母,不区分大小写,不需要回车:
  18. IF NOT "%Choice%"=="" SET Choice=%Choice:~0,1%
  19. if errorlevel 5 goto end
  20. if errorlevel 4 goto TianWei
  21. if errorlevel 3 goto LianTong
  22. if errorlevel 2 goto YiDong
  23. if errorlevel 1 goto DianXing
  24. :TianWei
  25. :LianTong
  26. :YiDong
  27. :DianXing
  28. pause
  29. :end
  30. exit
复制代码

作者: Echo11    时间: 2022-10-19 11:46

回复 3# holley


    可以的,我都是用的 /D /T 扩展来弄的菜单。
作者: thp2008    时间: 2022-10-22 11:24

出差了几天,不方便上网,现在才来回复。谢谢你们,测试没问题,原来自带参数。如此简单。




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2