What's New!

Chat with
Hackers

How to Defend
Your Computer 

The Guides
to (mostly) 
Harmless Hacking

Happy Hacker 
Digests (old stuff) 

Hacker Links 

Hacker
Wargames 

Meet the 
Happy Hacksters 

Help for 
Beginners 

Hacker 
Bookstore 

Humor 

It Sucks 
to Be Me!

How to Commit
Computer Crime (not)! 

What Is a 
Hacker, Anyhow? 

Have a 
Great Life! 

News from the 
Hacker War Front

More batch programming...

        3.- CHOICE
        Now we're ready to get the maximum power from the choice command. We saw before that errorlevels are some kind'a number that programs returned and so on. That was not very useful, I know, but for the choice program.
        The choice program takes a letter from the keyboard and returns an errorlevel in consecuence of the key pressed. The sintax is:
                CHOICE [text] [/C[:]keys] [/S] [/N] [/T[:]key,secs]

        Text is no more than the text to show when choice is runned.
        /C:keys Defines the possibles keys to be pressed. If no option is present, Y/N are the keys. For example:
                        CHOICE /C:ABCD
           Defines A,B,C,D as possible keys.
           If you press a not defined key, you'll hear a beep and will continue as if nothing was pressed.
        /S  Makes CHOICE case sensitive. By default, Z is equal to z for choice. With /S flag present, Z and z are different.
        /N  Choice shows the possible keys into brackets when is called. With the /N flag present, it does not, so that only the text you typed (if so) is shown.
        /T:key,secs  defines a key that is taken as default when secs seconds are passed. For example:
CHOICE  Chose drive /C:AC /T:C,5                

Shows the message "Chose drive [A,C]" (without quotes) and, if no key pressed, passed 5 seconds, choses C.

        **Way it works
        Now we know how to make the CHOICE sentence. Lets see what happens when CHOICE runs. It returns an errorlevel number corresponding to the key position in the /C flag. What???. Well, lets se an example:

                CHOICE /C:ABCD
                          |||L____>    D gives errorlevel 5
                          ||L_____>    C gives errorlevel 4
                          |L______>    B gives errorlevel 3
                          L_______>    A gives errorlevel 1

        Now you see that the errorlevel number depends on nothing but the position of the key that you gave to CHOICE. That is, when you type
                CHOICE /C:2567
        Pressing 2, CHOICE will give us errorlevel 1, 5 will give
errorlevel 2, 6 errorlevel 3 and 7 errorlevel 4.

        Lets see now what to do with errorlevel. If you remember the IF section, there was an:
                IF [NOT] ERRORLEVEL number command
        This evaluates the current errorlevel number. If condition is true the command is executed.

More batch programming--->>
 


Carolyn's most
popular book,
in 4th edition now!
For advanced
hacker studies,
read Carolyn's
Google Groups
Subscribe to Happy Hacker
Email:
Visit this group

 

Return to the index of Guides to (mostly) Harmless Hacking!

 © 2013 Happy Hacker All rights reserved.