Printer Friendly

Simplified use of batch files.

A Recent article in this column presented some excellent suggestions for creating batch files that enhance the user's efficiency with PCs.[1] I would like to present a slightly different take on the same topic.

Having a menu to choose from eases the repetitive chore associated with entering a program name or even having to move to a subdirectory first. Associated problems can frustrate first-time PC users and those for whom computer use does not come naturally.

Suppose you want to simplify program selection and maintenance by reducing the number of individual batch files you have to keep track of. You submit a budget request for Windows 3.1 (Microsoft Corp., Redmond, Wash.), sending your lab manager into gales of laughter as she criss-crosses your request in red ink. You go slinking out the door.

To make matters worse, your budget is so tight that you can't even upgrade your old release of DOS (disk operating system), which would have allowed you to insert a PATH command[2] into your AUTOEXEC.BAT. As if that weren't bad enough, your staff members, otherwise fine folks, are the world's worst typists. They frequently invoke "Bad command or filename" messages and call up the wrong programs with names that slightly resemble the names of the ones they want.

You have made up your mind that you want single keystroke entry to load your programs and you want a way to avoid getting undesired programs and messages. Furthermore, you want to be able to back out of your current program in an automated way that will support moving to another program easily, if desired. In sum, you want to enhance PC control and efficiency in your laboratory.

Fear not. You can do it without fancy software, piles of money, or even an upgraded DOS.

The batch file process described here makes use of a small program that utilizes the PC's BIOS (basic input-output system) interrupts and DOS interrupts. Interrupts are specific codes recognized by the PC's CPU (central processing unit) as commands for specific tasks. These commands are handled by a small program I call GRAB.COM, which the AUTOEXEC batch file calls into play.

GRAB.COM has a number of functions Figure 1). It uses the BIOS interrupt 16h (16 hexadecimal, equal to 22 decimal) to put the key character code (the character ascii value) into a PC register (data working area) called AL. It then does some comparing and, if appropriate, such as when we use the function (F) keys, it moves the key scan code from the AH register into our AL register, which then creates the exit code value. In our case, this happens whenever we use any of the 10 or 12 F keys (and DOS interrupt 21h). Because the F keys return no character value, they will leave a 00h value in the AL register.

Since only keys F1 through F10 should be used (you can expand the program to include F1] and F12, if you have one of the newer keyboards), we have to avoid using any others. Yet other keys (excluding CTRL, ALT, and SHIFT combinations of F1-F10) might accidentally be hit. Therefore, as protection, we will test for a non-zero value in the AL register. If a non-zero value is found, we will move a high number (255, or FFh) into AL and then have a consistent exit code for essentially all other unexpected keystrokes. (Remember, we haven't taken into account CTRL, ALT, and SHIFT-modified F keystrokes, since they can also return 00h to AL. You may want to expand the capability of the menu for more program calls than are defined here.)

We are now set up to deal with expected exit codes as well as unexpected ones. The only missing elements from our plan apart from our GRAB.COM file are:

1. A text file to serve as our menu;

2. The modifications to AUTOEXEC.BAT to take care of the ugly C: > prompt;

3. The batch file that will use our exit codes to determine what program we want to run;

4. Error messages for:

a. Non-assigned keys

b. Unassigned keys

5. An exit message if you allow exiting to DOS, explaining how to return to the menu; and

6. The batch file that supports re-entry to our menu system after using the DOS exit.

The menu I use is shown in Figure 2. I have changed the names next to the represented F keys to simplify editing. AUTOEXEC.BAT is modified to behave as detailed in the process flow description on page 73.

GETIT.BAT (Figure 3) utilizes labels (:LABEL) and a GOTO function to move to the specific area of the batch file that initializes the program you want to work with. Commands are included to restore the menu and wait for the next keystroke command after you have left the selected program.

When successfully installed together, these elements allow you and your users to invoke programs quickly and easily by single keystroke and then return to a clean, professional-looking menu. It does this without the operating overhead and loss of memory typical of GUIs, DOS shells, and other intervening software.

For convenience, I have included the commands needed to create GRAB.COM with the DOS utility program DEBUG.COM. I have also included the exit codes (scan codes) produced through various combination keystrokes. These permutations bring the total number of callable programs by F keystroke combinations to 40. For this article, I have limited selections to those associated with F1 through F10. This sampling should meet most people's requirements. Details of the file should be reviewed carefully. Please take note of comments (the notes following semicolons), since repetitive detail was omitted to save space.

Don't be intimidated by the size of the batch file. Once you have created it and used it for a while, you'll find modifications easy to edit in, including the menu text display file. I have used extended ascii characters (line drawing) where it seemed to be appropriate, but they are certainly not required. Feel free to use whatever screen and messaging representations you like best. GRAB.COM was created as much for fun as for functionality. Enjoy.

Process flow narrative

1. On bootup, the AUTOEXEC.BAT file issue a prompt command that does not display a DOS prompt. 2. It then clears the screen, calls up our menu SCREEN.TXT file, and types it to the screen. 3. AUTOEXEC calls GETIT.BAT, which stops processing after running GRAB.COM, awaiting our choice of keystrokes:

a. If F1 is depressed, the exit code generated is 59. The batch file determines that this ERRORLEVEL goes to label:8, which in turn invokes he batch commands that find and executed PROGRAM1. Existing brings us back to final steps in that portion of the batch file. The user is returned to the menu. The procedure is the same for F2 through F9, excluding F6.

b. If F6 is depressed, the ERRORLEVEL is 64, which goes to label :9, our DOS EXIT. As we exit, we type the MESSAGE.TXT file to the screen, informing the user to read the message. When the user presses any key, the program returns to the menu.

c. If F10, which is unassigned, is depressed, ERRORLEVEL 68 points to the portion of the file that types ERROR2.MSG to the screen and pauses for the user to read the message. When the user presses any key, the program returns to the menu.

d. If any other keys (excluding CTRL, ALT, and SHIFT-assisted are depressed, the ERRORLEVEL is forced to be 255. This moves the user to the :ERROR label and types ERROR.MSG to the screen, pauses to let the user read the message, and then returns the user to the menu when any key is pressed. An example of what I use: "I'm sorry, but I believe that you have either selected an invalid option or have keyed your entry in error. To return to the selection menu [the PAUSE command in the GETIT.BAT file will complete the sentence for the user]."


[1.] Sehloff J. Simplify humdrum PC tasks with batch files. MLO. September 1991; 23 (9):63-66. [2.] Disk Operating System, Version 3.10. Boca Raton, Fla: International Business Machines Corp; 1985; 7, 140-142.

General references

Dettman T. DOS Programmer's Reference, 3rd ed. Carmel, Ind: Que Corp; 1992. MS-DOS Version 2 Reference Guide. Houston: Compaq Computer Cotp; 1984. Thorne M. Computer Organization and assembly Language Pyogramming for IBM PCS and Compatibles. New York, NY: Benjamin/Cummings; 1991. Microsoft Macro Assembler Programmer's Guide: Version 6.0. Redmond, Wash: Microsoft Corp; 1991.

The author is information systems analyst, Palomar Pomerado Health System, Econdido, Calif.
COPYRIGHT 1992 Nelson Publishing
No portion of this article can be reproduced without the express written permission from the copyright holder.
Copyright 1992 Gale, Cengage Learning. All rights reserved.

Article Details
Printer friendly Cite/link Email Feedback
Title Annotation:Computer Dialog; includes related articles
Author:Macklin, Larry R.
Publication:Medical Laboratory Observer
Date:Sep 1, 1992
Previous Article:Sidestep legal pitfalls in employee promotion.
Next Article:Safety precautions ignored when babies visit the lab.

Related Articles
Simplify humdrum PC tasks with batch files.
NewsRx's 26 newsletters now on Dialog platform. (Partnerships).
Windows XP: Microsoft. (Software).
Adobe Photoshop 7.0, Photoshop Elements 2.0: Adobe. (new products).
Photoshop tips: automating Photoshop CS2.

Terms of use | Copyright © 2016 Farlex, Inc. | Feedback | For webmasters