my-server
← Wiki

AUTOEXEC.BAT

<code>AUTOEXEC.BAT</code> is a system file that was originally on DOS-type operating systems. It is a plain-text batch file in the root directory of the boot device. The name of the file is an abbreviation of "automatic execution", which describes its function in automatically executing commands on system startup; the filename was coined in response to the 8.3 filename limitations of the FAT file system family. In the autoexec.bat file one can execute every command being available either internally within the OS-specific command.com TSR or as an extra command (.com/.exe files)

Usage

<code>AUTOEXEC.BAT</code> is read upon startup by all versions of DOS, including MS-DOS version 7.x as used in Windows 95 and Windows 98. Windows Me only parses environment variables as part of its attempts to reduce legacy dependencies, but this can be worked around.

The filename was also used by (DCP), an MS-DOS derivative by the former East-German VEB Robotron.

In Korean editions of MS-DOS/PC&nbsp;DOS version 4.01 and higher (except for PC&nbsp;DOS 7 and 2000), if the current country code is set to 82 (for Korea) and no <code>/P:filename</code> is given and no default <code>AUTOEXEC.BAT</code> is found, <code>COMMAND.COM</code> will look for a file named <code>KAUTOEXE.BAT</code> instead in order to ensure that the DBCS frontend drivers will be loaded even without properly set up <code>CONFIG.SYS</code> and <code>AUTOEXEC.BAT</code> files.

Under DOS, the file is executed by the primary copy of the command-line processor (typically <code>COMMAND.COM</code>) once the operating system has booted and the <code>CONFIG.SYS</code> file processing has finished. While DOS by itself provides no means to pass batch file parameters to <code>COMMAND.COM</code> for <code>AUTOEXEC.BAT</code> processing, the alternative command-line processor 4DOS supports a <code>4DOS.INI</code> <code>AutoExecParams</code> directive and <code>//AutoExecParams=</code> startup option to define such parameters. Under Concurrent DOS, Multiuser DOS and REAL/32, three initial parameters will be passed to either the corresponding <code>STARTxxy.BAT</code> (if it exists) or the generic <code>AUTOEXEC.BAT</code> startup file, <code>%1</code> holds the virtual console number, <code>%2</code> the 2-digit terminal number (xx) (with 00 being the main console) and <code>%3</code> the 1-digit session number (y).

Windows NT and its descendants Windows XP and Windows Vista parse <code>AUTOEXEC.BAT</code> when a user logs on. As with Windows Me, anything other than setting environment variables is ignored. Unlike <code>CONFIG.SYS</code>, the commands in <code>AUTOEXEC.BAT</code> can be entered at the interactive command line interpreter. They are just standard commands that the computer operator wants to be executed automatically whenever the computer is started, and can include other batch files.

<code>AUTOEXEC.BAT</code> is most often used to set environment variables such as keyboard, soundcard, printer, and temporary file locations. It is also used to initiate low-level system utilities, such as the following:

  • Virus scanners
  • Disk caching software
  • Mouse drivers
  • Keyboard drivers
  • CD drivers
  • Miscellaneous other drivers

Example

In early versions of DOS, <code>AUTOEXEC.BAT</code> was by default very simple. The <code>DATE</code> and <code>TIME</code> commands were necessary as early PC and XT class machines did not have a battery backed-up real-time clock as default.

In non-US environments, the keyboard driver (like <code>KEYB FR</code> for the French keyboard) was also included. Later versions were often much expanded with numerous third-party device drivers. The following is a basic DOS 5 type <code>AUTOEXEC.BAT</code> configuration, consisting only of essential commands:

This configuration sets common environment variables, loads a disk cache, places common directories into the default PATH, and initializes the DOS mouse and keyboard drivers. The <code>PROMPT</code> command sets the prompt to "C:\>" (when the working directory is the root of the C drive) instead of simply "C>" (the default prompt, indicating only the working drive and not the directory therein).

In general, device drivers were loaded in <code>CONFIG.SYS</code>, and programs were loaded in the <code>AUTOEXEC.BAT</code> file. Some devices, such as mice, could be loaded either as a device driver in <code>CONFIG.SYS</code>, or as a TSR in <code>AUTOEXEC.BAT</code>, depending upon the manufacturer.

In MS-DOS 6.0 and higher, a DOS boot menu is configurable. This can be of great help to users who wish to have optimized boot configurations for various programs, such as DOS games and Windows.

The <code>GOTO %CONFIG%</code> line informs DOS to look up menu entries that were defined within <code>CONFIG.SYS</code>. Then, these profiles are named here and configured with the desired specific drivers and utilities. At the desired end of each specific configuration, a <code>GOTO</code> command redirects DOS to the <code>:END</code> section. Lines after <code>:END</code> will be used by all profiles.

Dual-booting DOS and Windows 9x

When installing Windows 95 over a preexisting DOS/Windows install, <code>CONFIG.SYS</code> and <code>AUTOEXEC.BAT</code> are renamed to <code>CONFIG.DOS</code> and <code>AUTOEXEC.DOS</code>. This is intended to ease dual booting between Windows 9x and DOS. When booting into DOS, they are temporarily renamed <code>CONFIG.SYS</code> and <code>AUTOEXEC.BAT</code>. Backups of the Windows 9x versions are made as <code>.W40</code> files.

Windows 9x also installs <code>MSDOS.SYS</code>, a configuration file, which will not boot Windows 95/98 if parameter<code>BOOTGUI=0</code> is loaded, and instead a DOS prompt will appear on the screen (Windows can still be loaded by calling the <code>WIN</code> command (file WIN.COM). This file contains some switches that designate how the system will boot, one of which controls whether or not the system automatically goes into Windows. This "BootGUI" option must be set to "0" in order to boot to a DOS prompt. By doing this, the system's operation essentially becomes that of a DOS/Windows pairing, like with earlier Windows versions. Windows can be started as desired by typing <code>WIN</code> at the DOS prompt.

When installing Caldera DR-DOS 7.02 and higher, the Windows version retains the name <code>AUTOEXEC.BAT</code>, while the file used by the DR-DOS <code>COMMAND.COM</code> is named <code>AUTODOS7.BAT</code>, referred to by the startup parameter <code>/P:filename.ext</code> in the SHELL directive. It also differentiates the <code>CONFIG.SYS</code> file by using the name <code>DCONFIG.SYS</code>.

OS/2

The equivalent to <code>AUTOEXEC.BAT</code> under OS/2 is the OS/2 <code>STARTUP.CMD</code> file. Genuine DOS sessions booted under OS/2 continue to use <code>AUTOEXEC.BAT</code>.

Windows NT

On Windows NT and its derivatives, Windows 2000, Windows Server 2003 and Windows XP, the equivalent file is called <code>AUTOEXEC.NT</code> and is located in the <code>%SystemRoot%\system32</code> directory. The file is not used during the operating system boot process; it is executed when the MS-DOS environment is started, which occurs when a DOS application is loaded.

The <code>AUTOEXEC.BAT</code> file may often be found on Windows NT in the root directory of the boot drive. Windows only considers the <code>SET</code> and <code>PATH</code> statements which it contains, in order to define environment variables global to all users. Setting environment variables through this file may be interesting if, for example, MS-DOS is also booted from this drive (this requires that the drive be FAT-formatted) or to keep the variables across a reinstall. This is an exotic usage today, so the file usually remains empty. The Tweak UI applet from the Microsoft PowerToys collection allows to control this feature (Parse AUTOEXEC.BAT at logon).

See also

References