DOS Menu | BATCH FILES | Full View |
Many who used BATCH files lightly in the good ole days of DOS may think they have no use in the Windows 95/98 environment. However there are many uses for them still. You can execute a batch file from a Windows Menu or Icon that will copy specific files then start a program.
Creating a DOS Programs Menu.DOS MENU BATCH FILEThis batch will create a menu to call up programs and return to the menu when the program is exited. It can be called up from a Windows 9.x Boot Icon to allow running several programs while at DOS without rebooting when you change games. The technique can be used for a variety of other functions. |
echo off :start cls echo. DOS Games Menu echo. echo. A) Game 1 echo. B) Game 2 echo. C) Game 3 echo. Q) Quit this menu and return to Windows. echo. echo. echo. choice /c:ABCQ /n Type the letter of your choice! if errorlevel 4 goto end if errorlevel 3 goto game3 if errorlevel 2 goto game2 if errorlevel 1 goto game1
:game1
:game2
:game3 :end |
The CALL brings you back to the menu when the program ends. The next command is then carried out. GOTO START takes you back to the beginning of the batch so you can choose another item without exiting. When you type Q when the menu is up, the batch ends. Replace game.exe with the file used to start the game. Also use the correct path for the game in place of the examples. You could have up to 36 options on the menu (26 letters plus 10 numbers) or keep it less cluttered by jumping to a second menu (if you have that many programs to list). I used Q to exit. But you can use whatever letter or number you want. Use the full path when entering CD. If you change to the game1 directory after running game2, and game2 is on the same drive, you would have to change to the root before you could go to game1 directory. This way, you don't have to have a fixed starting point for the batch. If the ANSI.SYS is loaded by the CONFIG.SYS file, you can add color to the menu and use other tricks. |
ADDING COLOR AND OTHER FUNCTIONS By adding the ANSI.SYS driver to your CONFIG.SYS file, you can use ANSI characters to decorate your batch file.Windows 9.x does not provide this function, so the driver must be loaded before Windows starts to use these functions at DOS or in a DOS window. For Windows 95 you would add the line: You can control the color of each character and its background color. You can also position, vertically and horizontally, each character on the screen. This allows you to have menus the react by changing colors to let you know if a choice is valid. Or it can toggle an item on and off. It all starts with an ANSI control code. You can create the character 許[ in the MSDOS EDIT program by holding down the CTRL key and typing P. Then let up the CTRL key and press the ESC key. This creates an arrow pointing to the left 許. Then you add the [ from your keyboard. The characters that follow perform the functions.
許[31m would be red text. 許[42m would be a green background.
So 許[31;42;1;5m would be a Bright red on a green background with blinking text. Note that each function is separated by a semicolon ; and the set concludes with (lowercase) m. Instead of the DOS CLS (Clear Screen), you can use 許[2J. Specify a background color followed by this syntax will paint the whole screen with that color. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
許[42m許[2J | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
will give a green background.
Note: The case is sensitive with ANSI codes. Upper case letters have different functions than lowercase letters. One important one to have handy is 許[3h. This sets the VGA mode to normal. I accidentally changed the mode with a wrong syntax. It made it hard to read the screen. This is not a major problem as you can close and reopen the window if you are in a DOS window. You have to reboot the computer if you are at DOS. By running this syntax, you can recover without doing either of those. Another function is the cursor placement. On a standard screen setting there are 80 horizontal columns and 25 vertical lines. You can place text or the cursor at any point with these codes: |
Creating an Interactive MenuThe Creating a DOS Programs Menu allows you to select from the list provided. Adding SET functions and using IF functions, the user can program tasks to be accomplished. If I wanted a batch file to PKZIP files from a directory into zip files, I can select which directories to copy before I start. |
echo off :start cls echo. if "%zipit1%" == "X" echo. X A) Windows if not "%zipit1%" == "X" echo. A) Windows if "%zipit2%" == "X" echo. X B) Program files if not "%zipit2%" == "X" echo. B) Program files if "%zipit3%" == "X" echo. X C) Root if not "%zipit3%" == "X" echo. C) Root echo. Z) Zip it now! echo. Q) Quit choice /c:ABCZQ /n Type the letter of your choice! if errorlevel 5 goto end if errorlevel 4 goto zipit if errorlevel 3 goto root if errorlevel 2 goto program if errorlevel 1 goto windows
:windows
:unzip1
:zipit |
Note: only the Windows selection is shown. When you select W the if "%zipit1%" checks the status of that variable. If the variable is on, the goto jumps to :unzip1 which unsets the variable. Then it returns to the menu. If the variable is off, it sets the variable and returns to the menu. This functions as a toggle, either setting the variable or unsetting the variable. When the menu is called up, each If function checks the status of its variable. The X between the ECHO and the ( toggles on and off as the variable is switched. Thus you get an indication of whether the item has been selected. Under the zipit heading, the files are copied only if the variable is set. If you have the ANSI.SYS loaded you can handle more information and use colors as well. You can have 2 columns of choices and direct the location of the X's. The choices can be fixed and only the X's change: |
echo off :start cls echo. echo. A) Windows B) Program files echo. C) Root echo. Z) Zip it now! echo. Q) Quit if "%zipit1%" == "X" echo. 許[2;3HX if "%zipit2%" == "X" echo. 許[2;38HX if "%zipit3%" == "X" echo. 許[3;3HX choice /c:ABCZQ /n Type the letter of your choice! |
The if "%zipit2%" == "X" echo. 許[2;38HX line will place an X left of the B) (row 2, column 38) choice if the variable is set. You can add color if you want. You can add other options where the color of the Windows choice changes if the directory is not detected. Use the dual line with If as in the first example. |
Running A Script With A Batch FileIf you had files to load that spanned several disks, you can create an install program. Let use ZIP'ed files that need to be installed to a directory on C drive. On the first disk you would create an INSTALL.BAT file. It might guide you through the process of creating a directory. When it begins the installation, it copies a second batch file into the destination directory, Let's name it insttemp.bat. This will actually run the installation. The install.bat in the first disk will call this file up at its end. The INSTTEMP.BAT will copy the files from the first disk that are needed. This may include PKUNZIP if the files are zipped. Once it has finished with the first disk, it will prompt you for disk2. If you have the ZIP files on each disk named for their disk (DISK1.ZIP, DISK2.ZIP, DISK3.ZIP, etc.), the batch can verify that the correct disk is in the drive before continuing. It can prompt you if the correct disk is not found. at its end it can delete any files only needed for the installation such as PKUNZIP. Then it can delete itself as its last command. The disks:
|
AND SAVING THEM WHEN YOU EXIT By typing a single word, up to 8 characters, Batch files can execute most of the functions you would have to accomplish by typing a series of commands. You can use a Batch File to: You can use this procedure whether or not you are using doublespace. However, with default settings, the Ramdisk can only manage 64 files or directories in its ROOT. You, therefore should have the game files in a subdirectory (g:\games\ for instance). With Doublespace there is only one file. You can change the settings to handle more. But using a subdirectory is easier. With Windows 3.1 and Windows 95 the batch file can be called to load the game, but you may have to use a separate Icon or menu selection to start the game after it is loaded. With MS-DOS 6.0 and later you can use the CHOICE command to create an interactive menu to run all of the games from a single batch file. A simple batch program to run DOOM from a PKZIP file would be:
The commands below DOOM are optional. R: is the Ramdrive. This example presumes that DOOM has all of its files in the DOOM directory. A batch file for loading a doublespaced game would look like this:
Once you have finished the batch file save with a name to call it up with such as DOOM.BAT. The extension must be BAT. When you type DOOM it will run. if you save it in a directory that is in path, can be called up regardless of what directory or what drive you are on. Type PATH at the DOS Prompt to see what directories are currently in path. |
Other Batch Information SourcesThe DOS Batch File Programming Handbook by Laurence Soucy
|
Comment to PoliTalk |
And That's My |