多字符批量选择菜单

时间:2016-06-05 01:04:03

标签: batch-file cmd

快速提问: 我已经在批处理文件中看到了单字符选择菜单,但是如何制作多个字符选择菜单?

这是一个例子(不起作用):

@echo off
echo Example Menu
GOTO AGAIN

:AGAIN
   CD /D "%~dp0"
   echo Restore, Apps, Restart

   set /p answer=
   if /i "%answer:~,1%" EQU "1" GOTO RESTORE
   if /i "%answer:~,1%" EQU "2" GOTO APPS
   if /i "%answer:~,1%" EQU "0" shutdown -t 0 -r -f

   if "answer"=="restore" GOTO RESTORE
   if "answer"=="apps" GOTO APPS
   if "answer"=="restart" shutdown -t 0 -r -f

:RESTORE
    start systempropertiesprotection -k
    GOTO AGAIN

:APPS
    start appwiz.cpl -k
    GOTO AGAIN

1 个答案:

答案 0 :(得分:0)

您必须使用变量"%answer%",而不是字符串"answer"

@echo off
echo Example Menu

:AGAIN
   CD /D "%~dp0"
   echo Restore, Apps, Restart

   set /p answer=

   if /i "%answer%" == "restore" GOTO RESTORE
   if /i "%answer%" == "apps" GOTO APPS
   if /i "%answer%" == "restart" GOTO RESTART

   echo That was not a valid option.
   GOTO AGAIN

:RESTORE
    echo You want to restore?
    GOTO AGAIN

:APPS
    echo You want apps?
    GOTO AGAIN

:RESTART
    echo You want to restart?
    GOTO AGAIN