Rob van der Woude's Scripting Pages

AUTOEXEC.BAT

As I explained in my Command Line Parameters page, batch files can only handle parameters %0 to %9

%0 is the program name as it was called,
%1 is the first command line parameter,
%2 is the second command line parameter,
and so on till %9.

However, there is one exception to this general rule: AUTOEXEC.BAT.

Since %0 is the program name as it was called, in DOS %0 will be empty for AUTOEXEC.BAT if started at boot time.
This means that, in AUTOEXEC.BAT, you can check if it is being started at boot time or from the command line, for example to prevent loading TSR's twice.

Besides that, it is not common for AUTOEXEC.BAT to process command line parameters, because of the way it is ususally called.

Of course, there is an exception to that rule as well, though most of you will probably never encounter it: OS/2 DOS sessions can use command line parameters for AUTOEXEC.BAT.

Windows 95 and 98 (and OS/2 and NT) can have multiple sets of AUTOEXEC.BAT and CONFIG.SYS files.
Windows 95 and 98 place those files in the root of the boot drive, distinguishing between them by giving them different extensions.

Windows NT usualy does have an AUTOEXEC.BAT and CONFIG.SYS, but doesn't use them by default.
To use AUTOEXEC.BAT to set environment variables in command line sessions you need to add or modify the following registry setting:

[HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Winlogon]
ParseAutoexec=1

Set it to 0 instead to disable it.

Warning: To use this feature you need to edit Windows NT's registry.
Changing the registry manually is a potential risk to your system; it may never function again.
Use this information entirely at your own risk.

Windows 2000 allows the use of any AUTOEXEC.BAT like startup batch file for command line sessions by introducing the AutoRun registry key, as in this example:

[HKEY_CURRENT_USER\Software\Microsoft\Command Processor]
AutoRun=C:\STARTUP.CMD

Replace C:\STARTUP.CMD with any other batch file you like to run at startup of command line sessions.

Warning: To use this feature you need to edit Windows 2000's registry.
Changing the registry manually is a potential risk to your system; it may never function again.
Use this information entirely at your own risk.

See this article at Windows Registry Guide for more details.


page last modified: 2011-03-04; loaded in 0.0042 seconds