I've written the following windows batch script for WinPE to make some tasks easier:
@ECHO OFF
CLS
:MENU
SETLOCAL
SET QUIT=FALSE
SET /P INPUTCHOICES=Type 1, 2, 3 or 4 and press ENTER:
CALL :EXECUTECHOICES %INPUTCHOICES%
ENDLOCAL
GOTO :EOF
:EXECUTECHOICES
IF [%1]==[] (GOTO :MENU) ELSE (CALL :%1)
SHIFT
GOTO :EXECUTECHOICES
GOTO :EOF
:1
cls
SET /P RB_OR_SD=Type R to reboot or type S to shutdown your PC when done, and press ENTER:
ECHO Performing task 1
ECHO.
pause
IF "%RB_OR_SD%"=="R" (GOTO :3)
IF "%RB_OR_SD%"=="S" (GOTO :4)
ELSE (GOTO :3)
:2
cls
SET /P RB_OR_SD=Type R to reboot or type S to shutdown your PC when done, and press ENTER:
ECHO Performing task 2
ECHO.
pause
IF "%RB_OR_SD%"=="R" (GOTO :3)
IF "%RB_OR_SD%"=="S" (GOTO :4)
ELSE (GOTO :3)
:3
cls
ECHO The system will now reboot
ECHO.
pause
GOTO :MENU
:4
cls
ECHO The system will now shutdown
ECHO.
pause
GOTO :MENU
GOTO :EOF
This script seems to be working fine, until the user inputs anything other than 1, 2, 3, 4, R or S.
In case of INPUTCHOICES
any wrong symbol just leads to "The system cannot find the batch label specified" message and the prompt reloads.
But in case of putting anything other than R or S into RB_OR_SD
the script just executes the next available batch label, which is absolutely not OK.
I want to limit the user input with exactly one symbol from the scope of 1
, 2
, 3
and 4
for the INPUTCHOICES
, and from the scope of R
and S
for the RB_OR_SD
.
Preferably making the user input case-insensitive.
Any help would be highly appreciated.