AUTOEXEC.BAT FILES
Your AUTOEXEC file is used to configure some things with DOS when your computer boots up. Generally it makes your command prompt more friendly looking and sets your PATH as well as start TSR's and start windoze 3.11. After you learn the basics, it really isn't to hard to set up an autoexec.bat file. First off, most texts that I have read say to CTRL+ALT+DEL every time to test out your changes. That isn't necessary unless you are testing for conflicts between TSR's or other memory modifying applications. If you are simply seeing if your change to a PATH command or something small will work right- just run your AUTOEXEC file. It's just a batch file named autoexec. I also recommend reading some of my Batchfiles page to better understand GOTO loops and IF statements if you are new to this stuff. Using some IF's and GOTO's will greatly advance your ability to create a truly helpful AUTOEXEC.BAT file. You will be able to change your computers configuration when needed a lot easier too. I will also show how to use some batch file enhancers like MS-DOS's CHOICE command and Norton Utilities BE command.
Normal stuff you'll find in yer AUTOEXEC.BAT file

Here's what you'll usually find in an AUTOEXEC file:

@ECHO OFF
C:\PROGRA~1\NORTON~2\NAVBOOT.EXE /STARTUP
PROMPT $P$G
LH D:\WINDOWS\alsinit.exe
PATH=D:\WINDOWS;D:\WINDOWS\COMMAND;D:\PROGRA~1\BITWARE;D:\GAMES\NES;
SET GRIP=D:\WINDOWS\GRAVIS

I have a rather complex AUTOEXEC file, so I chopped off all the confusing stuff and left a more usual one for us to study. In the first line, @ECHO OFF tells DOS not to print any of the following lines to the screen. The second line starts up my anti-virus program, Norton AntiVirus, and the switch /STARTUP tells it to do a quick startup scan and then shut itself off. Line three sets up your command prompt to show your current path and display a > after the path. The next line is a program to control my sound card. The LH in from of it tells DOS to load the program into the HIGH memory area. There are a number of switches the LH accepts, I'll list them later on. Line five line sets your systems PATH. The last line sets an environment variable so my joystick can find its configuration files. If you need more info on the following commands, "ECHO, PROMPT, PATH, SET", just click on their presence within this sentence.


More Things You Can Do

If you have a computer that uses and starts windoze 3.1 when it boots up you have seen how an AUTOEXEC.BAT file can start another program at boot up time. By placing a programs name within your AUTOEXEC file you will make it startup when your computer starts up. It would be wise to place your programs name at the end of the AUTOEXEC file so your PATH and other variables will already be in place. You will find WIN at the end of your AUTOEXEC file if you use windoze 3.1, WIN being the program that starts up windoze. Lets say your computer is an 8086 which can't run windoze 3.1; maby you just run WordPerfect 5.1 from it. If you just want your computer to start WordPerfect automatically you would place WP51 at the end of your AUTOEXEC file (Something I should probably mention is that any program run from your AUTOEXEC also needs to be within your PATH or you can just place the entire path to WP51 in your AUTOEXEC).

Another thing you can do is make your AUTOEXEC file react to environment variables set from within your CONFIG.SYS file (Only if you are using DOS 6 or higher). While I demand total control over my computer and require a complex menuing system, there are times I just want to turn it on, hit a single key, and get busy. I only have one menu, my CONFIG.SYS menu. I can control actions within my AUTOEXEC file by using the SET command from within a CONFIG.SYS menu. Since DOS 6 and higher will let you use SET from a CONFIG.SYS file, it's possible to pass variables to your AUTOEXEC file and make your life easier (Sometimes!) Example: I have one menu choice that allows me to prevent any unnecessary programs from being started up- including my virus scanner. When I select it from my CONFIG.SYS menu the menu then goes to a startup block that is relatively empty, except for a device line for HIMEM.SYS, DOS=HIGH,UMB, and two SET lines.
SET VSCAN=OFF
SET ANSI=OFF

My AUTOEXEC file checks for these two settings and reacts accordingly. If VSCAN=OFF it will skip the Virus Scan, and if ANSI=OFF it wont try to use escape sequences to make my prompt pretty colors (ANSI must be loaded in order to use escape sequences, which you can use to make your command prompt all different colors :-). I go into a lot more detail about how to do this on my CONFIG.SYS MENUs Page.


Making A Menu System

Now you have a decision to make, "Do I want or need some type of startup menu?". There are several ways to make a startup menu that allows you to choose a program to run. Before the existence of windoze many people designed batchfile systems that took windoze place. Lets face it, except for the extended memory availability windoze is just a fancy menu system. You can make a menu that will allow you to choose if you want to start windoze 3.1 and even windoze 95! I'll start with a very basic batchfile menu that the DOS bible from IBM and MS tell you how to do and then move on to some advanced systems that use the CHOICE program and Norton's batchfile enhancer BE.


Your Basic BATCHFILE Menu

Your AUTOEXEC.BAT file will start by printing a text file menu on the screen. Example:

===============================================================
                             MAIN MENU




               Press 1 And Return To Start Windows 3.11

               Press 2 And Return To Start Word Perfect 5.1

               Press 3 And Return Run Anti Virus




Just open EDIT.COM or the text editor of your choice and make up a nifty little menu screen for yourself. If you really wanted to get serious you could add some color the your menu with escape sequences, but I wouldn't recommend trying it if yer a DOS newbie. Lets call our menu screen MENU.TXT. To make your AUTOEXEC file display it, use the following line in your AUTOEXEC:
TYPE MENU.TXT
After your menu is displayed on screen, you will be dumped out to a DOS prompt. You can also get tricky an change your prompt to something like "Please select a number:". Now on to more batchfiles. You will make three very short batchfiles, 1.BAT, 2.BAT, and- you guessed it- 3.BAT. When you press 1 and enter you are running the batchfile named 1.BAT which in turn starts up Windows 3.11. Here's what 1.BAT will look like:

@C:\WINDOWS\WIN
@TYPE MENU.TXT

You should be able to understand what all goes on in there. The second line types our menu back on the screen after you exit from windows so you are ready to go again. The second and third batch files will look exactly the same except they will start their respective programs. You can make as many choices as you like in your menu. I have seen batchfile menu's like this with as many as twenty or so choices in them! That's MUCH more work than using some of the following ways to make a menu.


Adding A CHOICE To Your Menu

With DOS 6 there came a very useful program called CHOICE. It is used by your AUTOEXEC (Or any batchfile for that matter) to make menu systems easier to create. Here's the skinny on CHOICE:

CHOICE /C:   /N   /S   /T:c,nn   text

/C:          Specifies allowable keys. If none specified it defaults to YN for Yes and No
/N           Doesn't display choices or ? at the end of the prompt message
/S           Treats choice keys as case sensitive
/T:x,nn      Defaults to x after nn seconds
text         Prompt string to display
Undocumented: there are at least two special choice keys that you can use. If you have a * as one of the users choices with the /C: switch it stands for the escape key. A semicolon stands for the F1 key.

In your batchfile the IF ERROR LEVEL command is used to determine the correct action based on the choice the user selected. Here's a basic example that lets a user say YES or NO to an action:

@ECHO OFF
CHOICE /T:y,20 Do you want to start windoze
IF ERRORLEVEL 2 GOTO END
IF ERRORLEVEL 1 GOTO LOAD
:LOAD
C:\WINDOWS\WIN
:END

This is a very simple example, not to say a simple menu isn't useful. I have only used one switch, /T:y,20. Since CHOICE automatically displays a [Y,N] as a list of choices if none are listed, it isn't necessary to use the /C: switch. /T:y,20 will default to a Y answer after 20 seconds if nothing is selected. Now lets see what it looks like when we run this batchfile.

Do you want to start windoze [Y,N]?

Now lets go to a more complex menu with 4 different items to select from.

CHOICE /C:W,D,1,2 /T:W,15 Press W for windoze, D for DOS, 1 for DOOM, 2 for Nesticle
IF ERRORLEVEL 4 GOTO TWO
IF ERRORLEVEL 3 GOTO ONE
IF ERRORLEVEL 2 GOTO DOS
IF ERRORLEVEL 1 GOTO WINDOZE
:TWO
C:\GAMES\NES\NESTICLE.EXE
GOTO END
:ONE
C:\GAMES\DOOM.EXE
GOTO END
:DOS
GOTO END
:WINDOZE
C:\WINDOWS\WIN
:END

For more on using the GOTO command, visit my Batchfile Page. You will want to pay special attention to the order the ERRORLEVELs step down compared to the way you list the choice options. ERRORLEVEL 1 MUST BE THE FIRST CHOICE THAT YOU LISTED!! Your second listed option will be ERORLEVEL 2 and this pattern will continue until all of your options are taken care of. To my knowledge, there's no limit to the number of error levels you can use. You can also make submenus by using CALL to invoke another batchfile that uses CHOICE.

Sometime I will cover Norton's old Batch Enhancer, BE, but I don't have time right now for that.

If you still have any questions please E-mail me.


This web page is copyrighted by Nathan Heald. Reproduction is allowed as long as this message is not removed or modified in any way. Frames site  No-frames site. How to print pages off of this site. The official URL of DOS HeadQuarters is http://dos.rsvs.net