Windows 7 / Getting Started

Working with the Command Interpreter in the Registry

Many of the command line behaviors depend on registry settings. You can find these settings in the HKEY_CURRENT_USER\Software\Microsoft\Command Processor key for the local user and HKEY_ LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor for everyone using the same machine. The command interpreter looks for these registry settings when you don't provide an appropriate command line switch. If you don't see the registry entry, then the command interpreter uses a default setting. Local user settings always override the machine settings, and command line switches always override the registry settings. Here are the registry settings and their meanings.

AutoRun Defines the command that you want the command interpreter to run every time you open a command prompt. This value is of type REG_SZ or REG_EXPAND_SZ. Simply provide the executable name along with any command line switches that the executable may require. As with the string for the /C and /K command line switches, you can separate multiple commands using a double ampersand (&&).

EnableExtensions Specifies whether the command interpreter has extensions enabled. See the /E:ON command line switch description for a list of the applications that this entry affects. This value is of type REG_DWORD. Set it to enabled using a value of 0x1 and disabled using a value of 0x0.

CompletionChar Defines the file completion character (see the /F:ON command line switch for details). The default character is Ctrl+F (0x06). Use a value of a space (0x20) to disable this feature since the space isn't a valid control character. This value is of type REG_DWORD.

PathCompletionChar Defines the directory completion character (see the /F:ON command line switch for details). The default character is Ctrl+D (0x04). Use a value of a space (0x20) to disable this feature since the space isn't a valid control character. This value is of type REG_DWORD.

DelayedExpansion Specifies whether the command interpreter uses delayed variable expansion. See the /V:ON command line switch description for additional information. This value is of type REG_DWORD. Set it to enabled using a value of 0x1 and disabled using a value of 0x0.

Understanding Command Extensions

Command extensions are additional processing that the command interpreter provides for certain commands. The effects vary by command, but generally the commands receive additional functionality. In some cases, such as the del (erase) command, the extensions simply change the way the command works. The following list describes the command extension changes to each of the affected commands.

Assoc Microsoft hasn't documented how command extensions change the Assoc command. Even though Microsoft lists it as one of the commands that changes with command extensions, there isn't any obvious difference at the command line.

Call Accepts a label as the target for a call (rather than a filename as normal). This feature means that you can transfer control from one portion of a batch file to another. Using extensions means that you can call the label using call :Label Arguments. Notice that you must precede the label with a colon.

Chdir (CD) Displays the directory names precisely as they appear on your hard drive. For example, if a directory name has a space, you'll see the space when you change directories. Capitalization is also the same. A directory name that appears with an initial capital letter in Windows Explorer also appears that way at the command prompt. In addition, when you turn off the command extensions, the command doesn't treat spaces as delimiters. Consequently, you don't need to surround directory names with spaces or with quotes in order to obtain the correct results from this command.

Color Microsoft hasn't documented how command extensions change the Color command. Even though Microsoft lists it as one of the commands that changes with command extensions, there isn't any obvious difference at the command line.

Del (Erase) Changes the way the /S command line switch works. The command shows you just the files that it deletes, rather than showing you all of the files, including those that it couldn't find.

EndLocal Restores the command extension settings to their state before calling the SetLocal command. Normally, the SetLocal command doesn't save the state of the command extensions.

For Implements an expanded number of For command options. When working with directories, you process directories, rather than a list of files within a directory, using this call: for /D {%% | %}Variable in (Set) do Command [CommandLineOptions]. You can also perform recursive processing of a directory tree. Using this feature means that a single command can process an entire tree, rather than using individual commands to process a branch. Use the for /R [[Drive:]Path] {%% | %}Variable in (Set) do Command [CommandLineOptions] command line syntax to perform recursion. It's also possible to iterate through a range of values, similar to the functionality of the For loop used in higher level languages, using this command syntax: for /L {%% | %}Variable in (Start#,Step#,End#) do Command [CommandLineOptions]. Variable substitution is another useful feature that using command extensions provides (see the "Using Variable Substitution" section of the tutorial for details). Finally, you can perform complex file parsing and iteration with the command extension in place (see the "Performing Complex File Iteration" section of the tutorial for details).

FType Microsoft hasn't documented how command extensions change the FType command. Even though Microsoft lists it as one of the commands that changes with command extensions, there isn't any obvious difference at the command line.

Goto Defines a special label called :EOF. If you define a Goto command in a batch file with the :EOF label, the system transfers control to the end of the current batch file and exits. You don't need to define the label in the batch file to make this feature work.

If Defines additional comparison syntax that makes the If command considerably more flexible. See the "Using the If Command" section of the tutorial for details.

MkDir (MD) Lets you create intermediate directories with a single command. For example, you could define an entire subdirectory structure using MD MyDir/MySub1/MySub2. If MyDir doesn't exist, the system creates it first, then MySub1, and, finally, MySub2. Normally, you'd need to create each directory separately and use the CD command to move to each lower level to create the next subdirectory.

PopD Removes any drive letter assignment made by the PushD command.

Prompt Supports additional prompt characters. The $+ character adds one or more plus signs (+) to the command prompt for every level of the PushD command. Using this feature lets you know how many levels of redirection the PushD command has saved on the stack and how many more times you can use the PopD command to extract them. The $m character adds the remote name associated with a drive to the command prompt. The command prompt doesn't display any additional information for local drives.

PushD Allows you to push network paths onto the stack as well as local drive letters and path information.

Set Displays all currently defined environment variables when you use the Set command alone. Displays the specified environment variable when you supply an environment variable name, but not an associated value. If you supply only a partial variable name, the Set command displays all of the variables that could match that name.

SetLocal Allows the SetLocal command to enable or disable command extensions as needed to meet specific language requirements.

Shift Supports the /N command line option, which lets the Shift command shift variables starting with the nth variable. For example, if you use Shift /2 at the command line, then variables %0 and %1 are unaffected by the shift, but variables %3 through %9 receive new variable input.

Start Microsoft hasn't documented how command extensions change the Start command. Even though Microsoft lists it as one of the commands that changes with command extensions, there isn't any obvious difference at the command line.

[Previous] [Contents] [Next]