The Win2K Command Prompt Window

Find out how to customize and use the Command Prompt window, and explore Win2K's folder and filename completion feature.

Kathy Ivens

October 22, 2000

9 Min Read
ITPro Today logo in a gray background | ITPro Today

Win2K delivers new command-line power

In Windows 2000, Microsoft has made some long-overdue changes to the command-line interface. The Command Prompt menu item is on the Accessories submenu in Win2K, so if you're a command junkie, move the shortcut to a more convenient place. To do so, drag a copy of the shortcut to the Start menu or to the Quick Launch toolbar. You can also type

cmd

in the Run box to open a Command Prompt window.

Customizing a Command Prompt Window
In Win2K, the Control Panel Console applet that was available in Windows NT is gone. Instead, you use a Command Prompt window's drop-down menu to customize the window. Right-click the window's title bar to access the menu, which Figure 1, page 170, shows.

To customize the window, you can use either the Defaults or Properties menu item. Regardless of which option you select, the resulting Properties dialog box shows the same tabs with the same choices. However, each command affects your system differently.

Changing the Defaults dialog box settings permanently changes the default settings for all Command Prompt windows. The changes you make aren't enabled in the current window, but you'll see them in windows you subsequently open.

Changing the Properties dialog box settings changes the settings only for the current window, and the changes take effect immediately. However, after you modify the dialog box settings and click OK, you can choose to make your changes permanent for any Command Prompt window you open from the same source. For example, if you used a specific shortcut (e.g., the Start menu shortcut or a desktop shortcut you created) to open a Command Prompt window and made changes in the Properties dialog box, those changes appear in the next Command Prompt window you open from the same shortcut icon. If you typed

cmd

in the Start menu's Run dialog box to open a Command Prompt window, every time you use that method, your changes appear in the Command Prompt window you open. However, changes on a shortcut-by-shortcut basis are difficult to track, so if you know you want to change a Command Prompt window, change the default settings.

The Properties dialog box displays four tabs. The Layout, Colors, and Fonts tabs offer options you can use to change a Command Prompt window's size, appearance, and contents. The real power is on the Options tab, which Figure 2, page 170, shows, because this tab lets you change the window's behavior (e.g., Cursor Size, Command History, Display Options, Edit Options).

Cursor Size. Use the Cursor Size options to change the size of the blinking cursor. Small is an underline, Medium is a small square, and Large is a square that is the same size as the font.

Command History. The Command History group box offers three options. Buffer Size is the number of commands that the buffer stores. The Number of Buffers represents the number of processes that can maintain history buffers. Select the Discard Old Duplicates check box to have the system automatically eliminate duplicate commands in the buffer history. However, if you frequently execute a particular series of commands in the same order, retaining the duplicates can be handy.

Display Options. Use Display Options to change the size of a Command Prompt window from Window (the default setting) to Full Screen. To toggle between Window and Full Screen while you're working in the window, press Alt+Enter.

Edit Options. Instead of using a Command Prompt window menu's Edit command, you can choose QuickEdit Mode to copy and paste text automatically. Select Insert Mode to insert text at a command prompt instead of overwriting existing text. If you're not a terrific typist, this option is handy because you can back up through a command and correct your errors without retyping everything.

Using the Command Prompt Window
You can copy text from a Command Prompt window, but you can't cut text. To copy text when you've enabled QuickEdit Mode, drag your mouse to select text, then press Enter to place the text on the Clipboard. If you haven't enabled QuickEdit Mode, right-click the window's title bar, choose Edit from the drop-down menu, then select Mark. Drag your mouse to select the text, or position your cursor at the beginning of the text you want to copy and hold down the Shift key while you click the end of the selection. Press Enter to place the selected text on the Clipboard.

To paste text at a command prompt, position your cursor where you want to insert the text. If you've enabled QuickEdit Mode, right-click to automatically paste the text. If you haven't enabled QuickEdit Mode, right-click and select Paste from the pop-up menu that appears. If you prefer to use the keyboard instead of a mouse, press Alt+Space and then use e for enter and p for paste.

File and Directory Name Completion
The File and Directory Name Completion feature (aka folder and filename completion) lets you type a partial directory name or filename at a command prompt, after which the system automatically completes the entry. To use this feature, you simply enter a partial name followed by a control character. For example, you can enter

cd pro 

to access the Programs Files directory, or enter

myf 

to display the contents of myfile.txt. If multiple directories or files that match the characters you enter exist, press the control character again to move to the next instance. When you find the correct target, press Enter to complete the command. If no target matches your string, the system beeps.

Folder and filename completion isn't enabled by default, but you can enter

cmd /f:on

at a command prompt to invoke the feature for the current command session. Press Ctrl+D to complete a directory entry and Ctrl+F to complete a filename entry.

If you want to make the feature permanent, use a Registry entry to enable folder and filename completion for the computer or the current user. To enable the feature for the computer, open a Registry editor and go to the HKEY_ LOCAL_ MACHINESOFTWAREMicrosoftCommand Processor key. To enable folder and filename completion for the current user, go to the HKEY_CURRENT_USER SoftwareMicrosoftCommand Processor key. Open the value items named CompletionChar (for directory completion) and PathCompletionChar (for filename completion), and in hexadecimal notation, enter the control character you want to use. If the user-based key doesn't have the PathCompletionChar data item, you must add it.

For example, if you want to use the Tab key as the control character, enter 9 as the value. I find it easier to use the same control character for both computer and current user settings. If you use different control characters, the user settings take precedence over the computer settings.

The filename completion feature also works with directories because the feature actually searches for a complete path and matches it against both filenames and directory names. However, because the directory completion feature matches only against directory names, it works faster for directory searching than the filename completion feature does if both files and directories contain matching strings. Folder and filename completion automatically places quotation marks around names that contain spaces, so you won't see any error messages.

You can use the left arrow key to back up and retype the control character. This action discards all text to the right of the cursor, which is handy if you want to widen the search by shortening the string. After searching, if you edit the string and press the control character again, the system generates a new list and ignores the existing list of matches.

Win2K also has a command-line wildcard shortcut feature. You can enter a command and a string representing a partial name (of a directory or file, depending on the command) and end the string with a wildcard. Win2K executes the command against every matching directory or folder. Many users are aware of this feature and use it constantly, as in the command dir *.txt or dir tr*.

The wildcard feature also works with other commands, such as cd. If you enter the command

cd wi*

on a computer that has a directory named Winnt, the command finds the correct directory. However, if you enter the same command on a computer that has a directory named Winnt and a directory named Wizards, the command executes against Winnt only and never looks further.

Because the wildcard feature doesn't search further than the first match, this feature doesn't offer the flexibility and user control that the folder and filename completion feature does. Folder and filename completion displays each match as you continue to press the control character and lets you select the appropriate command by pressing Enter.

Open a Command Prompt Window in a Specific Location
As a command-line fanatic, I always want to find the easiest way to use a Command Prompt window. For example, I'd prefer to open a Command Prompt window in a specific location instead of using the cd command to navigate through the folders on my machine.

To put a command that opens a Command Prompt window on right-click menus in Windows Explorer or My Computer, you just need to make a Registry change. Open a Registry editor, and go to the HKEY_CLASSES_ROOTDirectoryshell key. Create a new subkey named OpenNew. Open the Default item in the right pane, and make its value Open A Command Window. (This Registry value represents the phrase that appears on the shortcut menu, so you can substitute a phrase of your own.) Create a new subkey named Command in your new OpenNew subkey. Open the Default item and enter

cmd.exe /k cd %1

as the value. (You're only changing the value of the Default item; you're not adding a new data item to the subkey.)

If you have multiple drives on your computer, you can add a similar command for the shortcut menu that appears when you right-click a drive object in Windows Explorer or My Computer. The instructions are the same as those for creating the command for folders, except that you use the HKEY_CLASSES_ROOTDriveshell key as the starting point. Also, the value of the Default item in the HKEY_CLASSES_ROOTDriveshellOpenNewCommand key is cmd.exe /k.

New Power for Familiar Commands
Some frequently used commands have additional functionality in Win2K. For example, dir /q displays the file owners' names. Prompt has some new characters, including $A (Ampersand—&); $C (Open Parentheses); $F (Close Parentheses); and $S (Space).

For those of us who depend on the Command Prompt window, the new command-line power that Win2K delivers is welcome. If you haven't experienced the speed and efficiency of working at the command line, the new functions should make experimenting with Win2K's Command Prompt window more alluring.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like