Jump to content

PE 2.0 Batch menu


agent20x

Recommended Posts

I'm trying to make a simple menu on my winpe 2.0 boot disk , but I get an error when I use "Choice" ie.

CHOICE /C:AB /N > NUL
IF ERRORLEVEL=2 GOTO OTHERS
IF ERRORLEVEL=1 GOTO 755
GOTO Start

Is this not possible with PE 2.0? Is there a way to do this but with different syntax?

Link to comment
Share on other sites


In DOS and Windows 9x, the CHOICE command allowed a batch file to accept single-character user input and perform different tasks based on the result. CHOICE is gone in Windows 2000 and XP, but the Command Extensions (enabled by default) enhance other commands in ways that let you work around the absence of CHOICE.

The SET command's /P switch lets you prompt for user input. For example, SET /P Choice=Type the letter and press Enter will set the environment variable Choice to whatever the user enters. SET also includes new syntax that lets you set an environment variable to a substring of another. The expression SET foo=%bar:~1,6% sets the variable foo to a substring of the variable bar starting at offset 1 (the second character) for six characters. The IF command has an /I switch for case-insensitive comparisons. Used together, those features let you create a menu much as you could with CHOICE.

The code below shows a simple example. This batch file first gets the user's input into the variable Choice. In case the user accidentally types more than one letter, it selects the substring consisting of only the first letter. Then it makes a case-insensitive comparison of that letter with each of the possible menu values. You can use this example as a starting point to build your own batch file menu in Windows 2000 or Windows XP.

@ECHO OFF
CLS
:LOOP
ECHO A. Menu item A
ECHO B. Menu item B
ECHO C. Menu item C
ECHO Q. Quit
:: SET /P prompts for input and sets the variable
:: to whatever the user types
SET Choice=
SET /P Choice=Type the letter and press Enter:
:: The syntax in the next line extracts the substring
:: starting at 0 (the beginning) and 1 character long
IF NOT '%Choice%'=='' SET Choice=%Choice:~0,1%
ECHO.
:: /I makes the IF comparison case-insensitive
IF /I '%Choice%'=='A' GOTO ItemA
IF /I '%Choice%'=='B' GOTO ItemB
IF /I '%Choice%'=='C' GOTO ItemC
IF /I '%Choice%'=='Q' GOTO End
ECHO "%Choice%" is not valid. Please try again.
ECHO.
GOTO Loop
:ItemA
ECHO Insert commands for Item A.
GOTO Again
:ItemB
ECHO Insert commands for Item B.
GOTO Again
:ItemC
ECHO Insert commands for Item C.
GOTO Again
:Again
PAUSE
CLS
GOTO Loop
:End

This batch file implements a simple menu system. It works only at the command prompt under Windows 2000, Vista, Winpe.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...