Windows 7 / Getting Started

Configuring the CMD Program

The previous section described how CMD reads and interprets commands. In this section, learn how CMD might be adjusted to better meet your own needs.

AutoRun

Normally, when it first starts, CMD examines the Registry for values under the keys

HKLM\Software\Microsoft\Command Processor\AutoRun

and

HKCU\Software\Microsoft\Command Processor\AutoRun

(HKLM and HKCU are short for HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER, respectively.) Any values with type REG_SZ (string) or REG_EXPAND_SZ (string with environment variables to be expanded) are taken as commands to be run when an instance of CMD first starts up.

AutoRun settings can be used to perform some of the functions that used to be provided by the AUTOEXEC.BAT file in DOS. In particular, you might want to run DOSKEY to set macros via an AutoRun command.

If necessary, you can disable AutoRun commands by starting CMD with /D on its command line, as I discuss later in the tutorial.

Environment Variable Substitution

As it examines command lines that you've typed or that it has read from a batch file, CMD replaces strings of the form %name% with the value of the named environment variable. For example, the command

echo %path%

turns into

echo c:\windows\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem

which then types this text.The command displays the value of the path variable. Environment variable substitution can be used anyplace on any command line, as long as the resulting text is a valid command. If you want to use an environment variable as part of a pathname, it's best to enclose the entire name with quotes because the environment variable might contain spaces. For example, to delete testfile.txt from the temporary folder, you should type

del "%temp%\testfile.txt"

Note: Environment variable names are not case sensitive. To CMD, %path%, %Path%, and %PATH% are all the same.

[Previous] [Contents] [Next]