Claudiu Dragan
Claudiu Dragan

Reputation: 39

Multi-character batch choice menu

Quick question: I've seen single-character choice menus in batch files everywhere but how do you make multiple character choice menus?

Here's an example (doesn't work):

@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

Upvotes: 0

Views: 1329

Answers (1)

Kittsil
Kittsil

Reputation: 2487

You have to use the variable "%answer%", not the string "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

Upvotes: 1

Related Questions