              
        GETTING STARTED
        HOW TO WRITE A BATCH FILE          
     ----------------------------------------

                                           
     On the previous page are the commands needed to get you
started. Now lets see how these commands work. To start you must
have a name for the batch file. 
     Lets say you have a modem and the program that runs it is
called Mymodem.  To start the program you must change to the
modem directory than type the letters to start the program.
Example:
C:\>cd my modem. When you press enter C:\>MYMODEM appears on the
screen. Your now in the directory of mymodem. To start the
program you must type mymodem.  Mymodem.exe is the full name but
you do not have to type the .exe. 
     We will call the batch file for this program MM. This will
stand for Mymodem.  To start to create the batch file we must
type copy con mm.bat at the prompt. Example:  C:\>copy con MM.bat
Next we press enter.  Now the cursor is under the word copy.
You will now type @echo off,  and press enter. Than type c:\ and
press enter.  Now you must type cd\mymodem,  and press enter. 
Now you type mymodem.  Then press enter.Now must you press the
ctrl key and Z. This will appear: ^Z. Which means you're done
writing the file. It will look like this: 
  
                    C:\>copy con MM.Bat                           
                    @echo off 
                    cls              
                    CD\ mymodem          
                    mymodem
                   ^Z

When you press enter you return to the prompt:  C:\>
To start the program just type MM at the prompt: C:\>MM
     The program will start with just those two letters. You have
permanently shorten the key strokes to start your modem program.
This type of batch file will work with any program running in MS-
DOS 5 thru 6.22.  You can also write it this way: 
                              echo off
                              c:\
                              cls
                              cd\mymodem
                              mymodem
 
      If you have a lot of MS-DOS programs that you do not have
in Windows you can use this batch file. But first let me explain
how it works so that you can understand what is going on:
echo off = will keep Dos from displaying the commands as they are 
           executed.
C:\> = your in C:\ directory from the start. This is really not   
       needed, but I sometimes use it.    
cls = this clears the screen of everything and blanks it out      
    until the program starts
cd\mymodem = this changes the directory to the mymodem directory
mymodem = starts the program                 
      
     This is a basic program to shorten the key strokes to start
a program. You will be surprised how fast the program starts up.
Your computer will seem to have increase in speed.
     You can delete the MM.bat file at any time. It is saved in
the C:\ directory. You can view the .bat file at any time by
typing at the prompt: c:\> type MM.bat. Then the MM.bat file will
be displayed on the screen. If you have made a mistake in the
spelling of any words or arrangements you can delete it, and
start over, or use the text editor to edit it. 
     You can and sometimes must modify the above batch file to
suit your needs.  This is a simple batch file that can be used
with almost any program. 
__________________________________________________________________
__________________________________________________________________

This is a short and quick introduction to the Edlin command.  Most
people have a newer version of MS-DOS and no need to use Edlin. 
It is out dated and no longer used, but you may have a older system
or come across an older system.
  
EDLIN: Used in MS-DOS version 4 and earlier to make batch files   
       and edit batch files. The following is the basic use of
       Edlin for more information consult your manual! 
       To use Edlin to make the same file:

                    c:\>EDLIN MM.BAT
                        NEW FILE
                        *I
                           1:* ECHO OFF
                           2:*cls
                           3:* CD\MYMODEM
                           4:* MYMODEM
                           5:* ^C
                        *E
Now press enter and you will be at the prompt.  The file is
saved.  To run the program just type MM at the prompt.
To make changes to the file type at the prompt (c:\>)
EDLIN MM.BAT.  You will get this at the prompt. Example:
C:\> EDLIN MM.BAT
     End of input file
     *
The file is now ready to be edited. You want to change the name
to mymouse directory.  Now type numeral 1 next to the * prompt
and the 1st line will appear ready to be edited.
Example: EDLIN MM.BAT
         END OF FILE
         *1
             1:*echo off  
Edit this line then repeat this method to edit any line in the
file. Example:  c:\> edlin mm.bat
                 end of input file
                 *1
                     1:* echo off
                     1:*
                     
                     2:* cls
                     2:*
                         
                     3:* cd\mymodem
                     3:* cd\mymouse
               
                     4:* mymodem
                     4:* mymouse
             
                     5:* ^C
                     5:*
                 *E
You have now changed the from mymodem to mymouse directory.
DO NOT make a batch for a program that is in your autoexec.bat
path. This can lockup the computer.




              ******* AUTOEXEC.BAT *********

CAUTION: DO NOT MAKE ANY CHANGES IN YOUR AUTOEXEC.BAT BEFORE 
	 MAKING A COPY OF THIS FILE! THIS FILE IS NEEDED WHEN
	 YOUR COMPUTER STARTS. ANY ERRORS IN THIS FILE WILL 
	 CAUSE YOUR SYSTEM TO LOCKUP OR FAIL TO BOOT!

	 IF YOU MAKE ANY CHANGES BE SURE TO DO THEM CORRECTLY!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 


     Do not use a batch file name to start a program that is in
your autoexec.bat path. with the same name. This can cause a
lockup. You should not use a batch file to open a program in your
path in the autoexec.bat. The autoexec.bat is a batch file. 
     
     To view your autoexec.bat type: type autoexec.bat at the
prompt.  Example: C:\>type autoexec.bat. You will use the same
procedure to view your config.sys. To make changes in the
autoexec.bat you must use a text editor.
     If you want to start a program automatically when you boot
up the computer you must put the program in your Path and place
the execution name of the program at the bottom of the
autoexec.bat. EXAMPLE AUTOEXEC.BAT that will start Wordperfect
5.1 program when the computer is booted. WP is the start up for
this program:   @echo off
                prompt $p$g
                path c:\; c:\dos;c:\wordperfect5.1;c:\mouse
                mouse
                set temp=c:\temp
                wp

                                                                  
     If you want your prompt after boot up and chose what program
to run yourself,  but you don't want to change directories or use
a batch file. You can put the wordperfect program in the
Autoexec.bat path as before but do not type WP at the bottom of
the file EXAMPLE:
@echo off
prompt $p$g
path c:\;c:\dos;c:\wordperfect5.1;C:\mouse
mouse
set temp=c:\temp

     At the prompt you would type WP and the program will start.
This is because the Autoexec.bat is a batch file and what ever
programs that are in the path can be started at the prompt.
     The semicolon must follow each program except the last one.
Look at the mouse in the path there is no colon after it. The
colon makes DOS search for another program.
CAUTION: ALWAYS MAKE A COPY OF THE AUTOEXEC.BAT

Customizing the Prompt:
     Your prompt (c:\>) can be customized. You can have a
message, date, time and almost anything you want. On my computer
I have the day, date, time, and a message along with the prompt.
Example: Wed 09-14-1994
         17:58:34.34
         HELLO! MAY I HELP YOU?
         C:\>
     There are several ways to have your prompt appear like the
one above: 1. Autoexec.bat  
           2. A batch file.
I'll start with the Autoexec. At the prompt position you must
delete $p$g. Now in their place type:
PROMPT $D$_$T$_$ HELL! HOW MAY I HELP YOU?$_$P$G
"$" The dollar sign is the metacharacter used with the prompt and
must be followed by a character. The "D" character stands for
date.
The $_ causes a carriage return which means that the next command
will be on another line. Wed 09-14-1994 is on one line by itself.
The "T" stands for time. It must look like this $T. To put it on
a line by itself just add $_.  
     Now the message must start with a dollar sign then a space,
and then type your message. After this you must go to another
line by using $_.  To get the current disk drive and directory
type $P. To get your ">" character after the c:\ type $G.   
     You can do the same thing with a batch file. Which will be
shown later.
 



 		******* MENU'S *******



     After a computer boots up a menu appears on the screen. This
menu shows the programs and the key strokes to start them.
I have also put into this menu what each program does.  This is
for other people that use the computer. This is a sample of what
a menu can look like:
                    

		     D0S DIRECTORY
                         MENU

  PROGRAMS                                             RUN

WINDOWS ----------MICROSOFT WINDOWS ------------------>WIN
AREACODE ------------ CHECKS AREA CODES -------------->AC
GIFVIEW ------------- GIF VIEWER --------------------->GIF
QMODEM ------------ TELECOMMUNICATIONS --------------->QM
LOTUS 123 -------- SPREADSHEET ----------------------->LO

WED 09-14-1994
18:06:52.92
HELLO! HOW MAY I HELP YOU
C:\>

     To have the above menu put on the screen automatically after
bootup I type on the last line in the autoexec.bat TYPE MENU.
This uses the TYPE command to put the menu on the screen.  The
last command in the autoexec.bat is the command that finalizes
the bootup sequence. In this case its TYPE MENU.  It puts the
menu on the screen. 
     Notice there are no long keystrokes to start a program.
There are batch files to start each program except windows.
Windows is in the autoexec.bat path. Games is five keystrokes,
but it is not a program it is a batch file to change the
directory to the directory where all the games are located.  
     Once in the game directory there is another menu on the
screen that shows all of the games,  and the keystrokes to start
them. Example:

                        GAMES MENU
                                                      
                                                      (TYPE)
   
SPELLING GAME --------------------------------------> SP
MATH AND SPELLING ----------------------------------> MS
CHESS ----------------------------------------------> CH
WHEEL OF FORTUNE -----------------------------------> WH
SLOT MACHINE ---------------------------------------> S1
SLOT MACHINE ---------------------------------------> S2
SOLITAIRE CARD GAME ---------------------------------> MO
BLACKJACK ------------------------------------------> BJ

C:\>GAMES

     Now this is a different setup for a reason.  All of the
games are in the same directory separated from the other
programs.  The Games directory has its own menu.  This can help
keep people in the games menu and not into the main programs
area. When a person exits a game they return to the Games Menu.
They do not get to the main menu or any other program that is not
a game.
     How did I get the computer to change directories?  A batch
file.  How did I get the menu on the screen?  The type command in
a batch file. How did I get a menu?  The menu is written in the
Editor, and saved with the name Games.MNU. The batch file that
brings the menu to the screen is called GAMES.BAT.   
     How did I write the menu?  First I had to know what programs
I wanted in the menu. I have some programs that are not on the
menu's. This hides them from other people. If some one types DIR
at the prompt all the files and programs in that directory will
appear on the screen. They will know what's really there, but
they would have to know what DIR is for. There are other ways
that I can really hide a program and files that DIR cannot find,
but I am not going to get into that now.
     Second we must make batch files for each of these programs.
You can use the samples on page seven or eight. All batch files
must end with the extension .bat. The computer will recognize
this as a batch file and execute the commands in it. Keep the
names of this batch file short because you want to shorten the
key strokes to start a program. Example: Qmodem is a program.
Qmodem is the keystrokes to start the program. For a batch file
to shorten the keystrokes name the batch file QM.bat. Now when
you type QM the program starts.
     Now that I had a list of programs and batch files for each
of them I opened the text editor. There I typed the menu the way
I want it to appear on the screen.  After this was completed I
open the drop down file menu and move down to SAVE AS.  I Pressed
Enter and the name box appeared.  In this box I typed the name
MENU.  This is the  main menu that appears on the screen after
bootup.
     After this is completed I exited the edit. At the c:\>
prompt use the type command to view the menu.  It looked the way
I wanted It to look.  Now I was ready to make the final step to
make this menu appear on the  screen automatically.
     At the prompt I typed: C:\>EDIT AUTOEXEC.BAT.  My
autoexec.bat appeared on the screen with a cursor.  Move the
courser down to the last line by using the arrows. On the last
line type: TYPE MENU.  This is the type command that will have
the menu appear on the screen.
     Now I open the file box and moved down to SAVE, and press
Enter.  I now open the file menu again and exited.  I  returned
to the prompt. I  Soft Booted the computer and everything went
right. The menu appeared on the screen after the bootup.  If it
did not I would have had to back track everything I did.
     This is how I got my main menu on the screen.  The games
menu works the same way except the type command to put the menu
on the screen is in a batch file.  The Games Menu was given the
name GAMES.MNU.  All of the games are in the same directory
(Games) and have batch files with two letter names.   I named the
batch file that puts the menu on the screen the Games.bat 
EXAMPLE:  COPY CON GAMES.BAT
          @ECHO OFF
          CD C:\GAMES
          TYPE GAMES.MNU
          ^z
     Now all have have to do to get the games menu on the screen
is type games.  The games batch file changes the directory and
puts the games menu on the screen.  I had to be careful that none
of the games have a file with the same name.  If they do you must
have that game,  or games in a different directory and a batch
file for each.  
       

 

	     ****** HAVING A COLOR MENU *******
    


     Now that you have a menu let's make that menu have color and
have a custom prompt.  Earlier in this book I said that there was
another way to have a custom prompt.  This is it! 
     In your batch file for the MENU.bat you can put a color
command to have the screen any color you want every time you're
at the prompt. You can also customize the prompt in the menu.bat
instead of the autoexec.bat.
      Before you can set screen colors you must load the ANSI.SYS
into the Config.sys. at the prompt type:  EDIT CONFIG.SYS. Your
config.sys will now be on the screen in the editor.  The commands
in the Config.sys is executed, and loaded to memory, and carried
out each time the computer is booted up.  THE COMPUTER MUST BE
REBOOTED SO THAT THE CHANGES THAT WERE MADE CAN TAKE EFFECT.

  
     CAUTION: MAKE A COPY OF YOUR CONFIG.SYS AND AUTOEXEC.BAT     
              BEFORE YOU MAKE ANY CHANGES TO THEM.  ANY ERRORS IN 
              EITHER OR BOTH CAN CAUSE THE COMPUTER TO            
              MALFUNCTION  AT BOOTUP. BE SURE YOU HAVE MADE ALL   
              CHANGES CORRECTLY. ALWAYS HAVE A FLOPPY DISK        
              AVAILABLE THAT CAN BOOTUP YOUR COMPUTER. ON THIS    
              DISK SHOULD BE,  YOUR COMMAND.COM.


     One of the things the ANSI.SYS does in a batch file is set
the screen colors. The ANSI.SYS can be installed by adding a new
Device or added to a device in the Config.sys. 
                          
                          
                           Example: 
                             OR                             
 DEVICE=C:\DOS\SETVER.EXE           DEVICE=C:\DOS\SETVER.EXE
 DEVICE=C:\DOS\HIMEM.SYS            DEVICE=C:\DOS\HIMEM.SYS       
 DOS=HIGH                           DEVICE=C:\DOS\ANSI.SYS
 DEVICEHIGH=C:\DOS\ANSI.SYS         DOS=HIGH
                                    DEVICEHIGH=C:\DOS





              SCREEN COLOR CODE CHART
     FOREGROUND                        BACKGROUND
CODE/VALUE        COLOR           CODE/VALUE     COLOR

 0 --------- black & white         40 --------- Black   
30 --------- Black                 41 --------- Red           
31 --------- Red                   42 --------- Green            
32 --------- Green                 43 --------- Yellow           
33 --------- Yellow                44 --------- Blue       
34 --------- Blue                  45 --------- Magenta      
35 --------- Magenta               46 --------- Cyan            
36 --------- Cyan                  47 --------- White       
37 --------- White       
                       
     The above color code chart is color codes to use in the
batch files.  The Foreground if for the print,  and the
Background is for the background color.  Black background and
white foreground is the default colors.  
     The ANSI.SYS device driver controls the communication
between your screen and keyboard,  and must have an escape
sequence that sets the screen color.  The easy way to do this is
with the Prompt command.  The  Prompt command uses two characters 
after the word prompt. The first character must be the dollar
sign. The escape sequence is "e" ($e).
     Everything after the escape sequence is read by the ANSI.SYS
and the ANSI.SYS follows the commands.  The command to set the
background blue is [44m.  The "m" ends the sequence.  The entire
sequence may look like this:  prompt $e[44m .  In a batch file it
may look lie this:  echo off 
                    prompt $e[44m

     Earlier in this book I said there were several ways to
customize the prompt.  In the autoexec.bat I put the time, date
and a message at the prompt.  The same thing can now be done in a
batch file and not the autoexec.bat.  The same sequence that was
in the autoexec.bat is used in a batch file.
     You can now have your menu appear on the screen
automatically after bootup, and have a blue background and white
foreground.
  
      EXAMPLE:  COPY CON MENU.BAT
                ECHO ON
                PROMPT $E[44m
                CLS
                PROMPT $D$_$T$_$ HELLO! HOW MAY I HELP YOU?$_$P$G
                ECHO OFF
                CLS
                TYPE MENU
                ^Z

     To have the ANSI.SYS read the characters the echo must be on
(echo on).  The first color sequence is for the background. If
you want a foreground to in a different color than white use its
color code after the background color code.  On the next line use
the CLS.  If you want to have a message put it on the next line
as above.  The prompt that appears on the screen is put there by
this batch file.  It does not have to be in autoexec.bat.  
     Now the next section of this batch file has the commands to
put the menu on the screen.  I had to use the echo off command in
the normal way.  
       I use this sequence in my computer.  There are other ways
to do the same thing but for now I am using this method.         
     My screen will now always have a blue background, and white
foreground.  When I change directories the screen will still have
the blue background because I have made this a part of my prompt.
     The colors that the programs use will be different.  What
ever colors the program uses will be what you see on the screen. 
The batch file that starts the program will have no effect on the
program colors. 
     There are some programs that start by their own batch file
within the program.  When I exit this type of program I end up at
the prompt and directory of that program.   To solve this problem
I had to find the execution (exe) of that program and make a
batch file for it which bypasses the programs batch file to start
it.  By doing this I can exit the program and have my menu back
on the screen automatically.             
     


	BATCH FILES CAN ALSO DO OTHER THINGS.  



Examples:
1. Password protection on a program or file to keep other people  
   from using sensitive files.

2. Use batch files inside of Microsoft Windows programs

3. Put a Calendar on the screen

4. Simplify system backup operations

5. Prevent accidental Hard Drive formatting                       

6. Ask user questions or give choices

     
     For advanced batch file information and Qbasic programming
     see the book list below.


-----------------------------------------------------------------

The following books are not an endorsment by the author or
G.L.R. Enterprises.




                     BOOK LIST 
                

Book Title :  MS-DOS BATCH FILES
Author :      Kris Jamsa

Publisher:    Microsoft Press
              A Division of Microsoft Corp.
              One Microsoft Way
              Redmond, Washington 98052-6399

ISBN 1-55615-638-3

Comments:  This is a guide to creating and using batch files for  
          the beginner to advanced.

----------------------------------------------------------------

Book Title :  Running MS_DOS QBasic
Author :      Michael Halvorson
              David Rygmyr

Publisher :   Microsoft Press
              A Division of Microsoft Corp
              One Microsoft Way
              Redmond, Washington 98052-6399

ISBN 1-55615-349-6

Comments: An easy way to learn basic programming. It is user      
          friendly. If you never tried programming before, or     
          you are intimidated by programming this book is for     
          you. There are  many useable sample programs in the     
          book. Have fun.



--------------------------------------------------------------
End Of File
