1.

Solve : choice.com question?

Answer»

I'm using "choice" in a batch file, similar to this:
CHOICE.COM /N /C:12 /T1,5

IF ERRORLEVEL ==2 GOTO TWO
IF ERRORLEVEL ==1 GOTO ONE

Is there a WAY to set this up so that any keystroke other than "2" will default to "1" or to stop invalid choices from stalling the timer?
If this isn't possible with choice, is there something else that will do this?
Thanks
RickIndirectly you already have set this up so that any keystroke other than "2" will default to "1". If a user does nothing for 5 seconds the default ("1") will be chosen automatically.

The /c switch sets up a key mask of ALLOWABLE entries. To set this up so that any keystroke other than "2" will default to "1" you would have to code every key on the keyboard in the key mask (all 101 or 102 of them except the "2" key) and code a corresponding goto ONE.

You cannot prevent the timer from stalling on an invalid choice.

Quote

If this isn't possible with choice, is there something else that will do this?
With a Win9x machine (CHOICE is not available on NT machines), you might be able to do something with a Windows Script.

Just what are you trying to do?

Hope this helps. This is a separate batch file I'm calling from autoexec.bat on win98. It overwrites the system.dat, user.dat, and a growing list of key system files and folders from copies on a CD. It runs automatically at each system reboot unless a certain keystroke is made. No screen display of the choices. This is PART of a bigger project using an "alternate registry" that gets overwritten during reboot.
I did try putting multiple entries in for one of the choices, something like:
CHOICE.COM /N /C:1[234567890qwertyuiop] /T1,5
The letters and numbers worked but the batch had problems when I added other characters. Could "IF" be used to handle to an invalid entry?
Rick
At first, a good solution might have been escaping special characters, but CHOICE only allows single character choices. Some special characters (/, \, &, and others) are used by DOS itself, which would probably CREATE some interesting but unexpected results.

You could try writing a QBASIC program.

Good luck. I don't know anything about QBASIC or any other programming language. That will have to wait until I have more time. I experimented with that batch file a little more and got some encouraging results. The first part looks like this:

@echo off
CHOICE.COM /N /C:1234567890qwertyuioplkcjhgfdsazxvbnm`[emailprotected]#$^&*()-=_+[]}{;:'",.? /T2,5

IF ERRORLEVEL ==2 GOTO TWO
IF ERRORLEVEL ==1 GOTO ONE

Written this way, any of the keys above default to "2" except for "1" which works as I wanted. The only keys I couldn't add to it are:
\|%><
Not quite what I wanted, but it will get the job done.
I do have another question for you. The rest of this batch file makes extensive USE of the copy and xcopy commands. Can the be used so that there is no output on the screen? I'd like to get rid of the "1 file(s) copied" and similar messages on the screen so that there are no indications that this is running.
Rick
Glad to see you got it worked out.

Code: [Select]
copy source target > nul
xcopy source target > nul


I don't know how much material I've looked at, but none of it explained > nul. That works great. Now I just need to go back thru this thing and double check all the paths and filenames. That and one more system backup just to make sure. Thanks again.
Rick


Discussion

No Comment Found