WordType Designs
Driven To Distractions©
The Sound of One Hand Clapping©


A rchive Date
[ 14-09-2000 ]
Category
[ Information Technologies ]
sub-Categoy
[ Microsoft ]

      [Using the NT4.0 Command Prompt's powerful features
      October 1997

      Windows Explorer is handy for shuffling files between folders, but it's utterly useless for renaming a group of files, quickly selecting a subset of files in a given folder, or automating a repetitive process with the help of a batch file. For those and many more tasks, a command line is essential. And anyone who appreciates the comfort and quick response of a command prompt will be overjoyed to see the improvements in NT 4.0. With virtually no fanfare, Microsoft's NT development team has beefed up the built-in command processor to impressive proportions. In this article, we'll show you how to customize the appearance and size of the Command Prompt's window and use its time-saving features.

      It's not a wimpy DOS window
      If you start a command window by using the Command Prompt shortcut on the Programs menu, you could easily dismiss the resulting black-and-white window as a simple DOS emulator. But nothing could be farther from the truth. For starters, the shortcut points to Cmd.exe, the 32-bit native Windows NT command processor. A full-featured, character-based interface to all of NT's subsystems and file systems, Cmd.exe lets you run programs, administer network resources, and cut and paste information between character-based and graphical programs. Yes, there's a Command.com too; it starts the 16-bit virtual DOS machine for running legacy apps, but you'll rarely need that oversimplified emulator.

      Customize using Console
      To edit a Command Prompt window's properties and default settings, use Control Panel's Console program. With this tool, you can configure the default appearance of any character-based application, including Command Prompt windows, FTP sessions, and other 32-bit console applications. You'll use the same dialog boxes to adjust the appearance and properties of a specific console application or Command Prompt shortcut.

      When you use Console, your changes apply to all newly created character-based windows. To adjust settings for only a specific shortcut or the current window, right-click on the shortcut icon or on the window's title bar or taskbar button, then choose Properties. The Properties dialog box for the Command Prompt shortcut is identical to the Console interface (don't be misled by the default MS-DOS icon that NT attaches to this shortcut--this is the correct Command Prompt). When you click OK, NT offers you a choice: You can change the settings just for the current window, or you can permanently modify the shortcut that you used to start the session.

      Customize your colors
      It's hard to take NT's command line seriously when it looks so clunky and DOS-like. Fortunately, replacing the hard-to-read white-on-black color scheme is easy. To begin, open Control Panel's Console applet; you can also right-click on a Command Prompt shortcut or the title bar of a running Command Prompt window, then choose Properties. In the resulting dialog box, click the Colors tab, and you'll see the options shown in Figure A. Use the radio buttons to select text and background colors from a palette of 16 choices, including easy-on-the-eyes combinations like black-on-gray.

      The default palette consists strictly of boring, basic colors, but you can actually choose from any color that your video hardware is capable of displaying. Use the Red, Green, and Blue color spinners to replace one or more of the standard colors with custom shades. There's no preview window, so your best bet is to use the Color selector from an applet like Paint to identify the appropriate RGB values, then manually dial them in here.

      You can also spruce up the default font while you're at it. The default Command Prompt font is the same ugly system font that appears in DOS windows. Ditch it in favor of a more stylish font. Open the Properties dialog box for the Command Prompt shortcut, then click the Fonts tab to select another raster font or, preferably, the TrueType Lucida Console font. If you choose the latter, you can also specify the size of the font and make it bold for greater readability.

      Resize the command window
      In a throwback to the thrilling days of 12-inch monitors and green screens, NT's default command window is 80 characters wide and 25 lines deep. This makes it difficult to see more than the briefest directory listings. Assuming that you're using a screen resolution of at least 1024 x 768, you should increase the size of the command window to 50 lines or more and widen the display to 100 characters or more.

      To adjust the size of an open window, simply drag one of its edges up or over. For a more permanent change, right-click the command window's title bar or taskbar button, then choose Properties. You'll find the Window Size settings on the Layout tab, shown in Figure B, where you can also set the starting position. Use the Window Preview in this dialog box to see the results of your changes.

      Increase the screen buffer
      Normally, any information that won't fit inside the friendly confines of the command window simply scrolls up and out of the window, never to be seen again. You're probably used to piping directory listings and Readme files through the DOS MORE command to page through lengthy listings and repeating the process if you inadvertently scroll past a section you wanted to see. That trick is no longer necessary.
      Instead, use the NT 4.0 command window's screen buffer to capture those listings so you can scroll back through them. The default screen buffer matches the window size of 25 lines and 80 characters, which effectively means there's no buffer at all. I've set my screen buffer to a hefty 9,999 lines without any ill consequences, although you may prefer a lower, more manageable number.

      Command extensions
      Microsoft's NT development team added or enhanced at least 18 commands for NT 4.0. For example, the familiar CD (Change Directory) now includes a /D switch that lets you change drives and directories in one command, a feature that comes in handy for batch files. Likewise, MD (Make Directory) now creates an entire directory tree with a single command, instead of requiring a monotonous series of MDs and CDs. Use the new FTYPE and ASSOC commands to add and edit file types and associations on the fly, bypassing the Windows Explorer File Types tab. The IF and FOR commands, used only in batch files, are also greatly enhanced. For a summary of the Command Extensions, type CMD /?.

      Know your history
      Once you've issued enough commands, you'll find yourself retyping the same ones over and over--unless, of course, you use NT's built-in command history to recall them from memory. The command history works a lot like the venerable DOSkey utility, except that you need not run a separate program. If you have DOS experience, most of the keyboard shortcuts will be familiar. Press the [F7] key to display a pop-up window that displays a list of previous commands, as shown in Figure C. Use the up and down arrows to move through the stack of commands. Table A shows other keys that perform similar DOSkey functions.

      Table A: These are useful funcion keys for the command line
      [F7] Pops up a window containing a scrolling, numbered list of previous commands.
      [F9]Lets you return to a specific previous command by entering its number.
      [F3]Recalls the last command you issued.
      [F2]Searches for a given character in the previous command.
      [F8]Marches backward through the command history.

      Edit the command line
      NT's command line is fully editable. You can use the [Ctrl]+arrow keys to move through the current command one word at a time. The [Home] and [End] keys move to the beginning and end of the line, respectively. The [Insert] key toggles between insert and overstrike mode. Press [Esc] to clear the current command and start over.

      Let the [Tab] key do the typing
      The trouble with long filenames is that they're so long. Entering convoluted paths to file and folder names, complete with spaces and backslashes, is tedious work (and a recipe for typos). So don't bother. Instead, make a simple Registry adjustment that lets you press the [Tab] key to automatically complete a file or directory name after you've typed a few characters.
      Of course, all the usual disclaimers about editing the Registry apply here. Open a Command Prompt window and type regedt32 to start the NT Registry Editor. Select the key
      HKEY_CURRENT_USER\Software\Microsoft\

      Command Processor

      then find the CompletionChar value in the right pane. Double-click that value and set its contents to 9 (the ASCII value of the Tab character. Save your changes and close the Registry Editor. Now when you type a few characters of the name of a folder or file and press [Tab], the NT Command Processor will AutoComplete the entry. For example, from the root folder C:\, type cd pr, then press [Tab] to log on to the Program Files folder with a minimum number of keystrokes. If more than one file or folder begins with that sequence of characters, just keep pressing [Tab] to cycle through the entire list. Pressing the [Tab] key at a blank command line cycles through every file and folder in the current directory, in alphabetical order.

      Better than Run
      One of the Run dialog box's most frustrating quirks is its inability to parse spaces if you want to open a folder or run a file stored in the Program Files folder. For example, to open a folder whose name contains spaces, you'll have to enclose the entire name in quotes. The same is true with the NT Command Prompt, with two important exceptions. First, because the enhanced CD command doesn't treat spaces as delimiters, you can use the CD command to move into a subdirectory whose name contains a space without surrounding the name with quotes. Second, the [Tab] AutoComplete shortcut that we suggested in the previous tip automatically adds quotes around long file and folder names that contain spaces.

      QuickEdit keys
      If you've ever gone through the tedious process of copying and pasting text from a DOS window, you'll truly appreciate this set of undocumented shortcuts. Before you can use them, though, you must select the General tab on the Command Prompt shortcut's Properties dialog box and check the QuickEdit box.

      Let's say you've used the DIR command to list the files in the current directory. Choose the file you want to run and mark it by holding down the left mouse button and dragging the pointer across the text. Simply right-click anywhere on the selected text to copy it to the Clipboard and clear the selection. To paste the Clipboard's contents in the current command window, point anywhere in the window and right-click. You can also paste the copied text into any application using standard Clipboard techniques.

      The familiar limitations of character-based windows apply, of course. You must mark off a rectangular section of the Command Prompt window for copying; sometimes this means the Clipboard contents will include a bit of unnecessary text.
      Directory settings
      Save your favorite settings in the DirCmd environment variable. For a listing of all the switches you can use to customize directory listings, type DIR /? at the Command Prompt. I prefer DIR /ON /X, which sorts the listing by name and shows the automatically generated 8.3 DOS-compatible name as well as the long NT filename. To make this setting the default, save the switches in the DirCmd environment variable.

      NT's interface for adding and editing environment variables is buried in Control Panel. Open the System applet and click the Environment tab, then look in the bottom pane for user variables, as shown in Figure E. Add the appropriate variable and give it the value you prefer, then click OK. Now whenever you launch a Command Prompt session, NT will remember your preference.

      To see the current contents of this and all environment variables, type SET at a command prompt. You can use any variable in a batch file by simply enclosing its name in percent marks. That will allow you to perform fancy operations with the IF command, such as comparing %username% with a specific value and executing a given command for only certain users. In fact, with the improvements in NT's Command Processor, batch files may enjoy a resurgence in popularity.

      Copyright © 1999, ZD Inc. All rights reserved. ZD Journals and the ZD Journals logo are trademarks of ZD Inc. Reproduction in whole or in part in any form or medium without express written permission of ZD Inc. is prohibited. All other product names and logos are trademarks or registered trademarks of their respective owners.
      Cross-Indexed:

      New document Icon


Some pages may require Adobe Acrobat Reader



Copyright and Fair Use Information: The contents of this web site is protected by international copyright laws and may not be reproduced in any form or manner whatsoever, if for the purpose of resale or solicitation of a donation. The essays included here, may be reproduced only if: 1)They are not altered in any way; 2) reproductions must be accompanied by this copyright page ; and 3) it is given freely and without charge.
Fair use: The fair use of copyrighted work, including such use by reproduction in copies or phonorecords or by any other means specified in above sections, for purposes such as criticism, comment, news reporting, teaching (including multiple copies for classroom use), scholarship, or research, is not an infringement of copyright. In determining whether the use made of a work in any particular case is fair use the factors to be considered include : (1) the purpose and character of the use, including whether the use is of a commercial nature or is for nonprofit educational purposes; (2) the nature of the copyrighted work; (3) the amount and substantiality of the portion used in relation to the copyrighted work as a whole, and; (4) the effect of the use upon the potential market value of the copyrighted work.

Home | About Narrative? |Contact
Copyright © 2025. All Rights Reserved
HAG122125 (1998 -2026)