DOS Menu BATCH FILESFull 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.
Adding Color to your batch file menus with ANSI codes.
Creating Interactive Menus.
Batch files scripts
Loading games with a batch file.
Other Batch File Links
 

DOS MENU BATCH FILE

      This 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
e:
cd e:\game1
call game.exe
goto start

:game2
c:\
cd c:\game2
call game.exe
goto start

:game3
x:
cd x:\game3
call game.exe
goto start

: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:
devicehigh=c:\windows\command\ansi.sys
to you CONFIG.SYS file. In DOS 6.x and older, it will be C:\DOS\ANSI.SYS.

      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.

Text colors:BrightBackground colors:
30;Black (Dark gray)Bright40;Black
31;RedBright41;Red
32;GreenBright42;Green
33;YellowBright43;Yellow
34;BlueBright44;Blue
35;MagentaBright45;Magenta
36;CyanBright46;Cyan
37;WhiteBright47;White
     

許[31m would be red text.
許[42m would be a green background.

Text attributes
0;All attributes offUndoes these particular settings.
1;Bright TextAs shown above.
5;Blinking text.If you are in Windows you must be in FULL SCREEN for this to work. I also found it would not blink if I was using a Norton Utilities NDOS command Processor.
7;Reverse Video on.This gives a negative effect.
8;Conceal on.This dulls the character, sort of the opposite of Bright (1).
     

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:
許[10;42H would put the location in row 10 and column 42. The uppercase H sets this function. If you wanted to center text, rather than spacing over to that point, you specify the line and column where you want the text to begin. This can get you around the shift that occurs if a line wraps because it is too long to fit on the screen. That could misalign all text that follows.

For more complete information on using ANSI, see MS-DOS v6.22 Help: ANSI.SYS from Vernon J Frazee, or type help ansi.sys at the MS-DOS 5.0 to 6.22 prompt.

 

Creating an Interactive Menu

      The 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
if "%zipit1%" == "X" goto unzip1
set zipit1=X
goto start

:unzip1
set zipit1=X
goto start

:zipit
if "%zipit1%" == "X" pkzip windows c:\windows\*.*
goto end

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 File

      If 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:
Disk 1 contains:
INSTALL.BAT
INSTTEMP.BAT
PKUNZIP.EXE
DISK1.ZIP
Disk 2 contains:
DISK2.ZIP
Disk 3 contains:
DISK2.ZIP
Disk 4 contains:
DISK2.ZIP
 

The INSTALL.BAT contains:
echo off
:start
cls
if "%instsrc%" == "" set instsrc=a:
echo. Install Source Path
echo.
echo. The current setting is: %instsrc%\.
echo. To change the path type C
echo. To accept this path type G
echo.
echo.
choice /c:gcq /n Type Q to quit! if errorlevel 3 goto end
if errorlevel 2 goto changes
if errorlevel 1 goto setdest

:changes
cls
echo. Type the new SOURCE path that you want as (example) C:\FILES
echo. Press Enter when you have finished and check the path.
echo.
echo.
fc con nul /lb1 /n|date|find " 1: ">$temp$.bat
echo set instsrc=%%5>enter.bat
for %%x in (call del) do %%x $temp$.bat
del enter.bat
set input=
goto start

:setdest
cls
echo. Install Destination Path
echo.
echo. The current setting is: %instdst%\.
echo. To change the path type C
echo. To accept this path type G
echo.
echo.
choice /c:gcq /n Type Q to quit!
if errorlevel 3 goto end
if errorlevel 2 goto changed
if errorlevel 1 goto unpack

:changed
echo. Type the new DESTINATION path that you want as (example) C:\files
echo. Press Enter when you have finished and check the path.
echo.
echo.
fc con nul /lb1 /n|date|find " 1: ">$temp$.bat
echo set instdst=%%5>enter.bat
for %%x in (call del) do %%x $temp$.bat
del enter.bat
set input=
goto setdst

:unpack
cls
echo. Unpacking
md %instdst%
if exist %instdst%\nul goto unpacking
goto end

:unpacking
cd %instdst%
copy cd %instsrc%\pkunzip.exe
copy cd %instsrc%\insttemp.bat
insttemp.bat
:end

 

The INSTTEMP.BAT contains:
echo off
pkunzip %instsrc%disk1.zip
cls
if exist %instsrc%disk2.zip goto disk2
if exist %instsrc%disk3.zip goto disk3
if exist %instsrc%disk4.zip goto disk4
echo.
echo.
echo.
echo. Insert disk 2 into %instsrc% drive and
pause
:disk2
if not exist %instsrc%disk2.zip goto missing2
pkunzip %instsrc%disk2.zip
:disk3
if not exist %instsrc%disk3.zip goto missing3
pkunzip %instsrc%disk3.zip
:disk4
if not exist %instsrc%disk4.zip goto missing4
pkunzip %instsrc%disk4.zip
cls
del
echo.
echo.
echo.
echo. Finished!
goto finished

:missing2
cls
echo.
echo. Disk 2 was not found in %instsrc% Drive!
echo. Please insert disk 2 into %instsrc% Drive and press C to retry!
echo. Or..
echo. Insert Disk 3 into %instsrc% drive and press S to skip Disk 2!
echo. Or..
echo. Press Q to Abort this installation.
choice /c:csq /n
if errorlevel 3 goto abort
if errorlevel 2 goto disk3
if errorlevel 1 goto disk2

:missing3
cls
echo.
echo. Disk 3 was not found in %instsrc% Drive!
echo. Please insert disk 3 into %instsrc% Drive and press C to retry!
echo. Or..
echo. Insert Disk 4 into %instsrc% drive and press S to skip Disk 3!
echo. Or..
echo. Press Q to Abort this installation.
choice /c:csq /n
if errorlevel 3 goto abort
if errorlevel 2 goto disk4
if errorlevel 1 goto disk3

:missing4
cls
echo.
echo. Disk 4 was not found in %instsrc% Drive!
echo. Please insert disk 4 into %instsrc% Drive and press C to retry!
echo. Or..
echo. Press Q to Abort this installation.
choice /c:cq /n
if errorlevel 2 goto abort
if errorlevel 1 goto disk4

:abort
cls
echo. The installation was aborted!
echo. The PKUNZIP.EXE file and the INSTTEMP.BAT were not deleted.
echo. You can resume the installation by typing:
echo. INSTTEMP while in this directory.
goto end

:finished
del pkunzip
del insttemp.bat
:end



 
USING BATCH FILES TO LOAD GAMES ON A RAMDISK
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:

  • Load a doublespace file onto the Ramdisk.
  • Mount the doublespace drive.
  • Start the game.
  • When you exit the game you can choose to update the stored files.
  •       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:
    echo off
    cls
    R:
    MD DOOM
    CD DOOM
    PKUNZIP C:\DOOM.ZIP R:\DOOM
    DOOM
    CLS
    ECHO EXIT MENU
    ECHO Type S to save the updated game and clear the Ramdisk.
    echo Type C to clear the Ramdisk without saving the game.
    echo Type Q to quit with no further action.
    CHOICE /C:SCQ /n
    if errorlevel 3 goto end
    if errorlevel 2 goto clear
    if errorlevel 1 goto save

    :save
    PKZIP c:\DOOM.ZIP R:\DOOM\SAVEGAME.DAT
    cd r:\
    deltree doom /y
    goto end

    :clear
    cd r:\
    deltree doom /y
    goto end

    :end

     

          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:

    echo off
    cls
    R:
    COPY C:\DBLSPACE.006 R:\DBLSPACE.006
    DBLSPACE /MOUNT=006
    s:
    CD S:\DOOM
    DOOM
    CLS
    ECHO EXIT MENU
    ECHO Type S to save the updated game and clear the Ramdisk.
    echo Type C to clear the Ramdisk without saving the game.
    echo Type Q to quit with no further action.
    CHOICE /C:SCQ /n
    if errorlevel 3 goto end
    if errorlevel 2 goto clear
    if errorlevel 1 goto save

    :save
    dblspace /unmount
    attrib -r -h -s r:\dblspace.006
    attrib -r -h -s c:\dblspace.006
    copy r:\dblspace.006 c:\dblspace.006
    attrib +r +h +s c:\dblspace.006
    cd r:\
    del dblspace.006 /y
    goto end

    :clear
    dblspace /unmount
    attrib -r -h -s r:\dblspace.006
    cd r:\
    del dblspace.006 /y
    goto end

    :end

    In this example S: is the assigned drive letter for the Double Spaced Ramdisk.

          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 Sources

    BATch file Links by Vernon Frazee
    The DOS Batch File Programming Handbook by Laurence Soucy


    PoliTalk Technical Menu
    E-Mail

    Comment to PoliTalk
    And That's My
    My Two Cents


    Updated September 11, 2003
    1