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.
In this tutorial:
- The CMD Command-Line
- CMD Versus COMMAND
- Running CMD
- Opening a Command Prompt Window with Administrator Privileges
- CMD Options
- Disabling Command Extensions
- Command-Line Processing
- Console Program Input and Output
- Using the Console Window
- I/O Redirection and Pipes
- Copy and Paste in Command Prompt Windows
- Command Editing and the History List
- Name Completion
- Enabling Directory Name Completion
- Multiple Commands on One Line
- Grouping Commands with Parentheses
- Arguments, Commas, and Quotes
- Escaping Special Characters
- Configuring the CMD Program
- The Search Path
- Changing the Path
- Predefined and Virtual Environment Variables
- Setting Default Environment Variables
- Built-in Commands
- Extended Commands
- Listing Files with the Dir Command
- Paginating Long Listings
- Printing Directory Listings
- Sorting Listings
- Locating Alternate File Streams
- Setting Variables with the Set Command
- Conditional Processing with the if Command
- Scanning for Files with the for Command
- Using the for Command's Variable
- Processing Directories
- Numerical for Loop
- Getting More Information