Prev | Current Page 361 | Next

John Paul Mueller

"Administering Windows Server 2008 Server Core"


CREATING BATCH FILES 137
When you use Choice by itself, it displays a simple [Y,N] prompt that doesn??™t accomplish much
unless you also provide an Echo command to describe what the user should say yes or no to.
Normally, you??™ll combine the Choice command with one or more arguments. Listing 5.1 shows a
simple example of the Choice command at work. You can obtain this example on the Sybex Web
site at http://www.sybex.com/WileyCDA/.
Listing 5.1: Using the Choice Command
Echo Off
REM Keep repeating until the user enters E.
:Repeat
REM Display the choices.
Choice /C DCE /N /T 15 /D E /M "Choose an option (D)isplay, (C)opy,
or (E)nd."
REM Act on the user choice.
If ErrorLevel 3 Goto End
If ErrorLevel 2 Goto Copy
If ErrorLevel 1 Goto Display
REM Copy the file.
:Copy
Echo You chose to copy the file.
Goto Repeat
REM Display the file.
:Display
Echo You chose to display the file.
Goto Repeat
REM End the batch processing.
:End
Echo Goodbye
Echo On
The code begins by creating a repeat label so the batch file continues working until the user
specifically stops it. Next, the code uses the Choice command to display the choices to the user.


Pages:
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
drukarki fiskalne kraków willa karmazyn międzyzdroje www.books61.hobbitstory.com terapia magnetyczna Informacje o hostingu