Smart Computing ® Smart Computing ®
Top Subscribe Today | Contact Us | Register Now   
middle
Home | Tech Support | Q&A Board | Article Search | Subscribe & Shop   


Using & Fixing Autoexec.bat Files Email This
Print This
View My Personal Library

Operating Systems
February 2000 • Vol.4 Issue 1
Add To My Personal Library

Using & Fixing Autoexec.bat Files

Jump to first occurrence of: [AUTOEXEC.BAT]

Even if you don't know exactly what your computer's Autoexec.bat file is, its name is hard to forget once you've heard it. The odd-sounding file name is short for automatically executed batch file, and it's an important part of the startup (boot) process on most PCs.

Although not absolutely required for starting a PC, the Autoexec.bat file takes care of a lot of your computer's housekeeping tasks and, if you use it effectively, customizes your PC's startup and user interface so you can work more efficiently.

An Autoexec.bat file is a batch program, which means it executes a series of several commands sequentially and automatically so you don't have to type them one by one at the command prompt (C:\>) of the Disk Operating System (DOS). Autoexec.bat is a special batch file that is automatically executed each time the computer is booted.

DOS automatically looks for a computer's Autoexec.bat file when DOS is booting up; it should be located in the root directory of the startup disk (usually C:\). If it's there, DOS runs Autoexec.bat, executing the commands contained within it. If it's not there, the PC will still start just fine, but it doesn't accomplish anything beyond its basic startup until you tell it explicitly what else to do.

Most PCs have an Autoexec.bat file, even though it's not required because it's a convenient way to get a PC up and running. If you or your computer vendor didn't set up an Autoexec.bat file when you first got your PC, an application you installed probably set one up for itself. Many programs write some setup commands into the Autoexec.bat file. If they don't find one, they'll make one.



Demystifying Autoexec.bat.

The Autoexec.bat file shown in the "A Sample Autoexec.bat File" sidebar is fairly basic; yours may also have device drivers placed into the file by the installation program for the device (such as the mouse, CD-ROM drive, or printer). Here's what the lines in the example file mean and what happens as a result of their inclusion in the Autoexec.bat file when you start your computer. (A device driver allows a peripheral, known as a device, to communicate with a computer.)

@ECHO OFF. This command tells the operating system that you don't want it to flash all the commands on-screen as it processes them. The @ sign is actually a line-by-line way of accomplishing the same thing. ECHO OFF tells the computer not to repeat any of the commands that you execute after this command; @ tells the computer to suppress this one, too. We're using the @ sign on just this line because this is the only line in the Autoexec.bat file that would otherwise flash on-screen (because it has to process it before it takes affect). If you want to use this function, @ECHO OFF should be the first line in your Autoexec.bat file.

PATH=C:\;C:\SYSTEM;C:\UTILITY; C:\BATCH;C:\PROGRAMS;C:\WIN DOWS. The PATH command tells your computer where to look for executable files (programs that launch the application and whose names end in .EXE, .BAT, and .COM). The PATH command should be placed at the beginning of your Autoexec.bat file; our placement, right after @ECHO OFF, is a good choice. Executable files are lists of instructions for a computer to carry out.

If you don't have PATH in your Autoexec.bat file, you must enter the full path name (drive and directory) as well as the program's executable file name each time you try to run a program or application, which is not a fun task. With the PATH set properly, you only need to enter the executable file's name, and DOS will search the specified directories in the order listed to find the program and run it.

PROMPT $P$G. This command sets the format of the command line prompt. As written here, it specifies that the prompt should show the drive and directory, known as the path ($P), followed by the greater than (>) symbol ($G). This is the format most people find useful. It is so commonly used in Autoexec.bat files that in DOS 6.0, Microsoft's developers preset the prompt to $P$G, so this entry is no longer necessary with DOS 6.0 and newer.

SET TEMP=C:\TEMP. This command sets the location of the directory into which DOS should place its temporary files.

SMARTDRV. This command automatically starts SMARTDrive, the disk-caching utility included in DOS 6.0 and newer. If you use another disk-caching program, you can have it run from the Autoexec.bat file the same way. This is a perfect candidate for inclusion in Autoexec.bat because to do its job of enhancing hard drive performance, a disk-caching program must be activated each time you boot the computer.

CLS. CLS clears the screen and brings the cursor to the top. It's especially useful if you do not have a blanket @ECHO OFF command at the start of your Autoexec.bat file because it clears the commands after they have executed. It also clears other startup information you don't need to see, such as the name of the read-only memory Basic Input/Output System (ROM BIOS) and other system startup information that precede the running of the Autoexec.bat file.

ECHO Good Morning. Even though you started with the @ECHO OFF command, you can specify items that you want to appear on-screen by typing echo before the message you want to appear. This command would make the words "Good Morning" appear on-screen.

WIN. Many Windows users go right to Windows when the computer is booted, never stopping in the DOS command line world and never even knowing how they got there.

Other users of Windows don't have the WIN command in their Autoexec.bat files and are simply typing it at the C:\> command prompt. If you're including WIN, or a command that starts any other kind of user interface (such as a DOS Shell) in your Autoexec.bat file, it should be the final command in the file.



Viewing & Editing Autoexec.bat Files.

Here are some reasons you might want to change your PC's Autoexec.bat file.

  • To automate commands you're typing each time you start the computer.
  • This article has given you some new ideas for handy things to include in the file.
  • Because you're installing or changing settings on software or hardware.


Before you make any changes, you should first look at what's already there. Because the Autoexec.bat file resides in DOS and executes DOS commands, you need to use DOS to view and edit it. You can use a viewer or editor program from within Windows or Windows 95 (Win95), but remember, you must restart the computer before any changes you've made will take effect.

Look at what's in your present Autoexec.bat file. To do this, go to the root directory on your PC's boot disk (usually C:\) by entering the command



cd c:\



at the DOS command prompt. This will bring you to the root directory. The prompt



C:\>



will be returned.

At the C:\> prompt, enter



type autoexec.bat



The contents of the Autoexec.bat file will be displayed on-screen (see Figure 1).



Figure 1. An Autoexec.bat file, such as this one, automatically executes commands that a user would have to enter one-by-one if it did not exist.
If the contents you're viewing include some items you want to remove, or if you want to add commands, you'll need to edit the file. The first step in editing an important file such as Autoexec.bat is to make a backup copy of it in its current state in case you need to restore the original version of the file.

At the C:\> prompt, enter



copy autoexec.bat autoexec.bak



This places the new backup copy in the same directory. If you make a mistake or don't like your changes, just rename the copy version back to "Autoexec.bat" (ren autoexec.bak autoexec.bat). Now you're ready to edit.



Editing Autoexec.bat.

To edit an Autoexec.bat file, you must use a plain text (ASCII) editor. If you use a word processor to do the editing, make sure it's saving a plain ASCII file, or you won't end up with a properly executable file. The easiest way to be sure you have a plain ASCII file is to use the text-editing program EDIT that's included with DOS (that's what is used for this example).

Adding a command. With few exceptions, most commands can be added anywhere (exceptions are noted above in the description of a typical file), but it's usually best to add commands to the end of the file, if only for the sake of organization. If there is a command at the end of your Autoexec.bat file that brings up a DOS Shell program (DOSSHELL) or Windows (WIN), insert your new line before that one. If the line you're adding is one that only serves its purpose when placed at the top, such as @ECHO OFF, then place it at the top.

At the C:\> prompt, enter



edit autoexec.bat



and the Autoexec.bat file will open.

Press the CTRL and END keys simultaneously to go to the end of the file, or use the Up and Down arrow keys to position your cursor where you want to add the line. Press the ENTER key to insert a blank line.

Type your command line carefully; use DOS Help or refer to your DOS manual to be sure you're using the correct command and syntax. Press ALT-F, then press S to save your changes. Press the ALT-F keys then press X to close the editor and return to the DOS prompt. Restart your computer.

Deleting commands. Before you delete a command, you might test how your Autoexec.bat file will run without it by putting a REM (Remark) command before it. A REM command disables the command that follows it. The REM command gives you an easy way to see how the file will run without the command before you remove it.

To delete a command from your Autoexec.bat file, follow these instructions.

At the C:\> prompt, type



edit autoexec.bat



Use the Up and Down arrows to place the cursor on the line you want to remove or change. Use the DELETE key to delete characters and lines you want to change. Edit carefully and use DOS Help or refer to your DOS manual to be sure you're using the correct command and that you've typed the command correctly.

Press the ALT and F keys, then S to save your changes. Press the ALT and F keys, then X to close the line editor program and return to the DOS prompt. Restart your computer.



Hiding Commands With REM.

The REM command is a great way for both novice and experienced hackers to edit Autoexec.bat files. As we discussed above, you can use REM to test what will happen if you delete a command from your Autoexec.bat and other system files plus make comments to yourself in the file. It's a good idea to add explanations of what commands do or why the file contains a certain command.

Using REM commands is easy: Follow the instructions above for editing an Autoexec.bat file and either type a new line with REM before it (to place a comment in the file) or place REM before a line in the file to see how the file will be executed without that command. Save the file and restart the computer to see the results of your changes.



Autoexec.bat Troubleshooting.

Most computer users will never experience any problems with an Autoexec.bat file, but DOS can choke on an Autoexec.bat file or even just on one of its commands. Most Autoexec.bat problems are easy to fix because most are caused by simple typographical errors. These errors and solutions apply for DOS, Windows 3.x, and Win95. Here's what to do when you encounter Autoexec.bat-related error messages.



Error message: Commands Entered in AUTOEXEC.BAT Are Not Being Executed

Solution: If none of Autoexec.bat's commands is being executed at startup, make sure your Autoexec.bat file is indeed named "Autoexec.bat" (look for typing errors), and that the file is in the root directory on your boot disk (usually C:\).

If just certain commands are not being executed, and you're not seeing error messages, then follow the instructions earlier in this article to view the file and check to see if the command that's not being executed is preceded by REM. If the command is preceded by REM, edit the file to remove the REM notation. Restart the computer to relaunch the Autoexec.bat file.



Error message: Error Message Returned at Conclusion of Startup: Bad command or file name

Solution: There are two potential problems. First, you may have a typographical error in one of the command lines in the Autoexec.bat file. Review the file to check the command lines for errors. If you see the error, edit the file to correct it, then restart the computer to see if your editing corrected the problem.

If you don't see the problem, then you need to watch how the Autoexec.bat is executed. If you have the @ECHO OFF command in your Autoexec.bat, edit the file, and type rem followed by a space at the beginning of the line on which it appears. This will allow all the commands in the Autoexec.bat to be displayed as they're executed. This will enable you to isolate the error because the error message will be displayed immediately after the command that caused it.

Either the PATH command doesn't list the path to this particular command, or the command that is returning the error message is above PATH in the Autoexec.bat file, so it is being executed before PATH has told the computer where to find it. Check the order of commands; PATH should be at or near the top of the file. If it isn't, add or move it.



Tips For DOS.

The Autoexec.bat is especially important when you're working in a DOS environment. The commands you use in Autoexec.bat affect how easy or hard it is to interact with DOS.

Although most commands in the sample Autoexec.bat file shown in the sidebar are generally good entries regardless of whether you're using DOS alone or with Windows, some commands only apply in one case or the other. A DOS-only system, for example, will not need the WIN command as shown in the example file (it would, in fact, return a "Bad command or filename" error message), but DOS might need the CD or DOSSHELL commands as shown below.

The two suggestions here for DOS users are also configuration-specific; both deal with optimizing memory for DOS, which is discussed in the article "Random-Access Memory: Step-By-Step RAM Solutions" in this issue. Note that commands listed here assume that the PATH command is in the Autoexec.bat file and that it points to the locations where the referenced programs and files are stored. If it is not, then you need to specify the full path in the command. See the sidebar "Getting Help In DOS" for tips on ensuring that you use the correct command syntax.

CD Directory. By typing cd directory at the C:\> prompt, the command changes directories to the one you most often work in. Use this command if you work in DOS only without Windows or a DOS Shell. Place it last in the Autoexec.bat file so your PC puts you into your most commonly used directory at startup.

DOSSHELL. This starts a DOS Shell program (the one that comes with DOS). The DOS Shell is an overlay to the DOS command line interface that gives you a more user-friendly, menu-based way of interacting with DOS. Do not include this command if you are running Windows. (Do not run Windows from within a DOS Shell.)

LOADHIGH <filename.ext>. This command loads the program, device driver, or terminate-and-stay-resident (TSR) program whose name follows the command into upper memory, thus freeing conventional memory for programs that need it. You can type loadhigh as lh.

EMM386. DOS cannot access memory beyond 1 megabyte (MB), so the operating system must be tricked. If your PC has a 386 or faster CPU, this command lets your PC convert extended memory to expanded memory and remaps it to upper memory blocks (UMBs), making DOS more memory-efficient. (NOTE: For this command to work, Emm386.exe must be installed as a device in Config.sys.)



Tips For Windows 3.x.

DOS still runs the show for Windows 3.x users; the startup process still begins with DOS, which still executes Config.sys and Autoexec.bat files if they're present. The Autoexec.bat file you have set up for DOS should work fine for Windows, with just a few exceptions, as noted in the command descriptions. See the sidebar "Getting Help In DOS" for tips on ensuring that you use the correct command syntax.

SHARE. The SHARE command should be running, either in Autoexec.bat or, with a slightly different syntax, in the Config.sys file. SHARE helps ensure the system continues to operate when two programs try to access the same file. This isn't an issue except on networked computers using only DOS. But with Windows, there are times when multiple programs are running in Windows and are trying to access the same files.

WIN. As shown in the example file, the WIN command, placed last in the Autoexec.bat file, puts you directly into Windows after the startup process is completed.



Tips For Windows 95.



Although theoretically possible (and reasonably well-publicized), Win95 installations without DOS are rare. If you do not install DOS with Win95, you won't have an Autoexec.bat file, but you probably do have DOS already. If you are upgrading to Win95 from a prior version of Windows or from DOS, don't delete your Autoexec.bat file. The Win95 setup makes some modifications to Autoexec.bat to eliminate redundancies and incompatibilities, but there may be application-specific entries that you want to keep. Leave them alone, and they'll still be run in sequence at startup.

Here are some examples of the changes that Win95 makes to your Autoexec.bat file after it makes a copy of your version (Autoexec.dos).

  • It places REM in front of incompatible TSRs so they will be bypassed at startup.
  • It deletes WIN and SHARE.
  • It creates a TEMP (temporary) directory.
  • If you had one, it updates the PATH statement to include the file paths it needs, so it will read as follows: PATH=C:\ WINDOWS;C:\WINDOWS COMMAND; your prior entries.
  • It places REM in front of any device driver entries that are no longer needed (because of Win95 device support) so they will be bypassed during startup.
  • It removes more than 40 other unnecessary or incompatible commands.
    Whatever you do, leave these things out of your Autoexec.bat file:
  • Mouse references (mouse support is built into Win95)
  • SMARTDrive (disk caching is built into Win95)
  • The path to another version of Windows in the PATH= statement



With Win95, the Registry and Io.sys take over for Autoexec.bat and Config.sys. Applications and devices used to write to the Autoexec.bat and Config.sys files to make sure the computer could find them and give them what they needed to get going; now the device support built into Win95 and the Registry and initialization (.INI) files take care of the new 32-bit applications. Older 16-bit applications and drivers for devices not supported by Win95 are still going to look to Config.sys and Autoexec.bat.

As operating systems advance, Config.sys and Autoexec.bat will fade into computer history. But in the meantime, they are an important part of your computer's configuration.

by Tyna Callahan and Kimberly Maxwell




A Sample Autoexec.bat File


Following is an example of a typical Autoexec.bat file. All its commands could be entered individually at the C:\> prompt, but that's a tedious process because the user will want them entered each time the computer starts up. An Autoexec.bat file automates the command entry and execution process. Each line's meaning is explained in detail in the main article.



    @ECHO OFF
    PATH=C:\;C;\SYSTEM;C:\UTILITY;C:\BATCH;C:\PROGRAMS;C:\WINDOWS
    PROMPT $P$G
    SET TEMP=C:\TEMP
    SMARTDRV
    CLS
    ECHO Good Morning
    WIN





Getting Help In DOS


Need some assistance when using DOS? Here are some commands that can help.



    HELP

    Entered at the DOS prompt (C:\>), this command brings you to DOS' Help file contents so you can choose your topic or command. Typed with a DOS command following it ( help path, for example), it tells you what the command does, as well as its proper syntax.




    < COMMAND> /?

    Type any command at the DOS prompt (C:\>), followed by a space and the characters /?, and DOS gives you a short summary of usage, along with syntax rules for the command.




    FASTHELP

    FASTHELP gives a short summary of what each command does. Entered by itself, this command returns a listing in alphabetical order with short definitions. Entered with a command, it gives the same short description, but adds syntax rules for the command.










Want more information about a topic you found of interest while reading this article? Type a word or phrase that identifies the topic and click "Search" to find relevant articles from within our editorial database.

Enter A Subject (key words or a phrase):
ALL Words (‘digital’ AND ‘photography’)
ANY Words (‘digital’ OR ‘photography’)
Exact Match ('digital photography'- all words MUST appear together)





Home     Copyright & Legal Information     Privacy Policy     Site Map     Contact Us

Copyright © 2009 Sandhills Publishing Company U.S.A. All rights reserved.