In this section, I'll tell you a bit about how cmd may be adjusted to better meet your own needs. Some of these settings change how the Command Prompt window appears, whereas others change the software environment itself. If you were used to the MS-DOS environment, some of the software settings will be familiar, although the method of changing them is quite different. Console Window PropertiesYou can make several changes to the appearance of console program windows . For better visibility, or to make a program look more like it's running under MS-DOS, you can press Alt+Enter to run the program in full-screen mode. If you run a DOS graphics program, this will happen automatically. In this mode, the program takes over the whole screen and all other Windows features disappear. You can always press Alt+Enter to bring back the Windows desktop. You can set the screen mode and the number of lines that the window can scroll using the window's Properties dialog box, as shown earlier in Figure 9.5. You can also set the window's colors and font. Usually, you won't need to adjust the font. It's best to simply resize the window in the normal way and Windows will size the characters accordingly . Changing the Search PathBy default, Windows sets the PATH environment variable to a standard list of Windows folders. If you plan on writing your own programs, batch files, Windows Script Host scripts, or other application programs, it's a good idea to place them in a folder of their own and then add that folder to the path. You can change the search path in any of three ways. First, you can set a new value for the PATH environment variable using the set command, as in this example: set path=c:\bat;%path% This makes the folder c:\bat the first folder in the path. The ;%path% ensures that the prior PATH folders are retained in the path list, otherwise you wouldn't be able to run programs not in c:\bat . Second, you can use the path command, which is a "shortcut" version of set path : path c:\bat;%path% These commands have the same effect: They set the environment variable PATH to c:\bat , followed by the previous PATH definition. Note If the folder you're adding to the path has spaces in its name, put quotes around the name . You could also add a new folder to the end of the search path with a statement like this: set path=%path%;"c:\bat" The ordering only matters if there are versions of the same command in more than one folder in the path; the version in the first folder to be searched will be the one that Windows runs. Tip If you mess up the path and cmd stops working, just close the Command Prompt window and open another. You'll be back in action. Putting your own folders ahead of the Windows folders in the list can be a blessing or a curse. If you create a program or batch file with the same name as a standard Windows program, yours will run instead of the standard program. If this is what you want, great, but if not...the result can be very confusing. The path and set commands only change environment variables for the current instance of the cmd program. If you close the Command Prompt window and open a new one, you'll be back to the initial default PATH . The third way of changing the PATH makes the change appear in all future cmd prompt windows. To do this, you'll need to make the change on the System Properties dialog box, as I'll discuss shortly under "Setting Default Environment Variables." Predefined and Virtual Environment VariablesEnvironment variables can be set in any of six places. If a given variable name is set in more than one place, the last definition encountered is used. The sources are processed in the following order:
The following variables are defined by default for all users (systemwide):
In addition, when command extensions are enabled, several "virtual" environment variables are available. The following environment variable names are computed dynamically if used on a command line or in a batch file:
These entries don't really exist in the environment; cmd just fakes it by substituting the appropriate value when it runs into, for example, %date% . If you define an environment variable with one of these names, your fixed defined value will always supercede the dynamic value. The maximum size for an individual environment variable (name, equals sign, and value) is 8,192 bytes. The total size of all environment variables must be less than 65,536KB. Setting Default Environment VariablesTo define environment variables permanently so that they are defined whenever you log on, click Start, right-click My Computer, and select Properties. Next , view the Advanced tab and click Environment Variables. Windows will display the dialog box shown in Figure 9.6. Figure 9.6. The Environment Variables dialog box lets you edit default environment variables for your account or for all users.
The top part of the dialog box lets you define the default variables for your account. You can click New to add a new variable, or you can click Edit or Delete to modify an existing entry. The lower part of the dialog box edits the default variables provided to all user accounts. These settings can only be edited by an Administrator account, and the settings may be overridden by user-specific entries. An interesting feature of this dialog is that in most cases, if a variable is defined in the User Variables list, the user version overrides the System version. However, in the case of the PATH variable, the User version is prepended to the System version. This helps prevent users from accidentally ending up with a PATH that is missing all of the standard Windows program folders. Here's an example. If the System PATH is defined as C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\WBEM and the User PATH is defined as c:\bat;"c:\program files\my special stuff" then the user's actual PATH environment variable will be set to [View full width]
at logon. Note If you're familiar with Windows Script Host, you can also modify the default environment variables with WSH scripts by modifying the WshShell.Environment("system") and WshShell.Environment("user") collections. I recommend that you create a folder to contain your own personal batch files and scripts, perhaps named c:\bat , and add it to your user PATH as discussed here. This way, your scripts and batch files can be run from any command prompt you own, without worrying about where they're stored. The Adjustable PromptI mentioned earlier that the command prompt shows you the shell's current directory. For example, the prompt C:\Documents and Settings\brian> shows that my current drive is C: and the current directory is C:\Documents and Settings\brian . If you manage computers or use networking software to work with several computers at once, you may find yourself confused at times, wondering to which computer a Command Prompt window belongs! You can modify the command prompt to display more (or less) information using the hieroglyphics listed in Table 9.9. cmd examines the PROMPT environment variable for any of the character codes listed in the table and replaces them with the appropriate information. Table 9.9. Prompt Codes
To set the prompt, construct the desired series of codes and issue the command set prompt= codes or use the shortcut prompt codes For example, prompt $t$h$h$h$h$h$h $m$p$g prints the time, backspaces over the number of seconds, adds a space, and then prints the network path and current drive and directory. The resulting command prompt looks like this: 19:19 \sumatra\cdrive K:\> If you mess things up, prompt $p$g restores the prompt to its default value. Tip To make a permanent change to your prompt, right-click My Computer, choose Properties, Advanced, Environment Variables and then add a PROMPT definition under User Variables for.... AutoRunNormally, when it first starts, cmd examines the Registry for a value named AutoRun under the keys HKLM\Software\Microsoft\Command Processor and HKCU\Software\Microsoft\Command Processor ( HKLM and HKCU are short for HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER , respectively.) AutoRun 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; first the HKEY_LOCAL_MACHINE value is examined, and if defined, run, and then the HKEY_CURRENT_USER value is checked. 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 can use it to run DOSKEY to set macros via an AutoRun command (we'll discuss this later in the chapter). If you want to run more than one command with the AutoRun feature, create a batch file, and have the AutoRun value specify this batch file's name. If necessary, you can disable AutoRun commands by starting cmd with /D on its command line, as I'll discuss later in this appendix. Note This "autorun" setting is not related to the Autorun feature that launches applications or plays media when you insert a CD or DVD. Configuring the MS-DOS Command EnvironmentAs mentioned earlier, Windows XP uses a command prompt shell program named cmd.exe . As it turns out, to maintain maximum compatibility with old MS-DOS programs and old batch files, the original MS-DOS command.com shell is actually still available. The clunky old batch file language we all knewand loved?is still there. Here's how it works: If you run an MS-DOS program in a Command Prompt window, cmd assumes that you're going to work in the 16-bit world for a while. So, when the DOS program finishes, the window switches to the command.com shell. You'll notice several differences:
These changes make it more likely that old programs and batch files will be able to run. However, if you want, you can keep cmd.exe as your command shell even when using MS-DOS programs, by configuring the MS-DOS environment. To maintain compatibility with as many old DOS programs as possible, ntvdm can be configured to mimic an older environment. You can configure ntvdm's memory and window options through a properties dialog box, and you can configure the virtual DOS environment itself through configuration files that mimic the old CONFIG.SYS and AUTOEXEC.BAT files. Here is how the default configuration works:
These settings should work for most MS-DOS programs. You can modify these files to make changes that will apply to all MS-DOS programs, or you can create customized versions for specific applications; we'll discuss this in the next section. If you need specially tuned DOS environments for special applications, you may want to configure Windows shortcuts for these applications, or at least create shortcuts that open custom-configured Command Prompt windows. To create a customized MS-DOS environment, right-click the name of the MS-DOS program you want to run and select Properties. If you change any of the default properties and save the settings, Windows will create a file with the same name as the program file, but with extension .PIF . This .PIF file holds the customized settings. It is listed in Explorer as a "Shortcut to MS-DOS Program." Use this shortcut to run the program. If you need to run a batch file before running the program, follow this same procedure, but create a shortcut to the batch files instead of the program itself. Note You must use the shortcut to start the MS-DOS program in order to take advantage of any configuration changes you've made. If you run the .EXE file directly, Windows will not know to look at the .PIF (shortcut) file. Window and Memory OptionsThe Properties dialog box for an MS-DOS application shortcut ( .PIF file) lets you set the virtual MS-DOS environment's memory display and mouse properties. To customize these properties, right-click the MS-DOS application file itself, or if you've already created customized properties, you can right-click the MS-DOS Application Shortcut icon, and then select Properties. Here are the most common settings to change:
In the next sections, I'll describe all the property pages in more detail so you can see what configuration options are available. The General, Security, Summary, and Backup pages (if they appear on your system) are the same as for any other Windows file, so I won't describe them here. Program SettingsThe Program tab displays a typical Shortcut property page and has the following settings (see Figure 9.7):
Figure 9.7. The MS-DOS Shortcut Program tab. The Advanced button lets you specify a custom config.nt or autoexec.nt file.
Tip If a DOS program fails to run, uncheck this box and try to run the program again. You'll then have time to read any error messages that appear. The Program tab also lets you specify alternate configuration and startup batch files to use instead of CONFIG.NT and AUTOEXEC.NT . To change the configuration files associated with a shortcut, click the Advanced button and enter the paths and names of the desired files. The default values are %SystemRoot%\SYSTEM32\CONFIG.NT and %SystemRoot%\SYSTEM32\AUTOEXEC.NT . I will describe the settings in these files shortly. Tip If your MS-DOS program has timing or speed problems, it may be that it expects to be able to change the settings of the PC's timer chips. If you click the Advanced button and check the Compatible Timer Hardware Emulation option, the problem may go away. Font SettingsThe Font tab lets you select the font used when the program is running in a window. The default setting, Auto, lets Windows resize the font as you resize the window, but you can specify a fixed size. If you do, the window will not be resizable. Tip If you want to switch to a fixed font size, you can do it while the program is running. Right-click the upper-left corner of the program's window, select Properties, and view the Font tab. Make any desired changes and then choose Save Properties for Future Windows with the Same Title when Windows offers you this option. Memory SettingsThe Memory tab, shown in Figure 9.8, lets you specify the type and amount of memory to make available to the MS-DOS program. The plethora of memory types came about as different ways of coping with the original PC's limited memory hardware options. Some programs can use any type of memory, but others specifically require access to XMS or EMS memoryyour program's installation instructions will tell you what type of memory it requires or can take advantage of. Here's a list of the settings:
Figure 9.8. The Memory tab lets you make various memory formats available to the DOS program.
Screen SettingsThe screen settings let you determine whether the program has "direct" access to the whole screen at startup. These settings include the following:
When the MS-DOS program is running and attempts to change the display from text-based to graphical, Windows will automatically switch to full-screen mode. You can manually switch back and forth between full-screen and window mode by pressing Alt+Enter. If the program is using a text display, you can continue using it in window mode. If it is displaying graphics, however, the program will be suspended (frozen) and minimized unless it's in full-screen mode. Windows, unfortunately , can't display a little windowed version of the DOS graphical display. Miscellaneous SettingsThe Miscellaneous Settings tab determines how the program behaves when it's running in a window. Most of the settings are self-explanatory. The tab is shown in Figure 9.9. Here are the less obvious settings:
Figure 9.9. The Miscellaneous Settings tab lets you control the program's use of the mouse and keyboard.
Compatibility SettingsWindows XP compatibility settings let you limit the abilities of the virtual display adapter seen by the MS-DOS program. The relevant settings are Run in 256 Colors and Run in 640x480 Screen Resolution. If your MS-DOS program has problems displaying graphics screens, try checking these boxes. CONFIG.NTJust as MS-DOS used CONFIG.SYS to make initial memory allocations and to load device drivers, ntvdm uses CONFIG.NT to configure the virtual DOS environment. The default CONFIG.NT file as installed by Windows is located in \windows\system32 and contains several pages of comment text, which you may want to read. Here are the default settings in this file: dos=high,umbdevice=%systemroot%\system32\himem.sys files=40 You can edit CONFIG.NT to modify the defaults for all MS-DOS applications, or you can create alternate files using a different name for use with specific applications. In the latter case, use the Advanced button on the Program Settings properties page for the program's shortcut to enter the alternate filename. I'll use the name CONFIG.NT in the discussion that follows to refer to any config file. Note For starters, if you use MS-DOS database applications, you will probably want to increase the FILES= setting in CONFIG.NT to 100 or more. You may also want to add the ANSI cursor control module with the line device=%systemroot%\system32\ansi.sys Other than these two adjustments, it's unlikely that you'll need to make any other changes. The full set of options for CONFIG.NT is listed in the rest of this section. COUNTRY= xxx [ , [ yyy ][ , [ path ]] filename ]] tells MS-DOS to use an alternate character set and date/time format. xxx is a country/region code, yyy is an optional code page designator, and filename designates an optional driver containing country code information. If you use the virtual MS-DOS environment outside the U.S., view the Help and Support Center and search for "country." DEVICE= [ path\ ] filename [ parameters ] loads a device driver. Hardware device drivers will almost certainly not work in Windows XP, but certain software services implemented as drivers will. Examples include himem.sys , which is required to let MS-DOS programs access memory above 640KB, and ansi.sys , which interprets character sequences that some DOS programs use to control the cursor. These drivers are located in folder %systemroot%\system32 . DEVICEHIGH= [ path\ ] filename [ parameters ] or DEVICEHIGH [ SIZE = xx ][ path\ ] filename [ parameters ] similar to device but attempts to load the device driver into upper memory blocks, leaving more conventional memory for MS-DOS applications. If there is insufficient room in upper memory or if the device himem.sys has not been loaded, the driver will be loaded into conventional memory. The alternate size= xx format lets you specify the number of bytes of high memory that must be free; xx must be specified in hexadecimal. DOS= [ HIGH LOW ][ , UMB NOUMB ] DOS=HIGH specifies that MS-DOS should move parts of itself into the high memory area (the first 64KB past 1MB). The default is LOW , where DOS resides entirely in conventional memory. The optional keyword UMB indicates that DOS should make upper memory area blocks (the memory beyond 1MB+64KB) available for DOS, devices, and programs. DOSONLY If this keyword is present in CONFIG.NT, COMMAND.COM will only be permitted to run MS-DOS programs. Normally, if you typed the name of a Windows program at its command prompt or in a batch file, it would run the Windows program in a separate environment. This may disrupt some DOS terminateand-stay-resident (TSR) programs, so the DOSONLY option lets you prevent this from happening. ECHOCONFIG If the command ECHOCONFIG appears, CONFIG.NT commands are echoed to the Command Prompt window while ntvdm is initializing. The default is for the commands not to be displayed. FCBS= n File Control Blocks (FCB) is an archaic structure used by DOS version 1.0 programs to manage files. Few, if any, surviving MS-DOS programs require FCB, but if you have one, you can use the FCBS statement to instruct ntvdm to allocate space for n of them. (At this late date, if you do need them, you'll already know it, as you'll have had to deal with this on every prior version of DOS and Windows.) FILES= n sets the maximum number of concurrently open files available to MS-DOS applications. The default value is 20 . You may want to increase this number to 100 or more if you use database applications such as MS-DOS FoxPro. INSTALL= [ path\ ] filename [ parameters ] loads a TSR into memory prior to running AUTOEXEC.NT . One program that you may need to install in AUTOEXEC.NT is setver.exe . Setver intercepts programs' requests to find out what version of DOS is running, and it lies to them. Its purpose is to let you run programs that would otherwise be unhappy to find that they're running on DOS version 5.0, which is what ntvdm would tell them. If your MS-DOS application complains about the DOS version number, open the Help and Support Center and search for "setver." NTCMDPROMPT By default, when an MS-DOS program is run from the command line or a batch file and exits, cmd runs command.com to handle all further commands. This makes it possible to run old MS-DOS batch files. If you specify NTCMDPROMPT in CONFIG.NT , cmd will not run command.com , but will remain in control between MS-DOS programs. This lets you write modern batch files to use with MS-DOS programs. SHELL= [ path\ ] filename [ parameters ] specifies an alternate shell program to use if you do not want to use command.com as the MS-DOS shell. You can also use this command to specify command.com with startup options. For example, the entry shell=%systemroot%\system32\command.com /E:2048/P requests 2048 bytes for environment variables. The /P option is required to prevent command.com from exiting after processing one command. STACKS= n,s When a hardware interrupt occurs, ntvdm needs "memory stack" space to temporarily store information for the interrupt handler. The stacks option lets you instruct ntvdm to allocate separate stack space for interrupt handlers. The numbers n and s instruct ntvdm to allocate n blocks of s bytes each. n can be or 8 through 64 . s can be or 32 to 512 . The default values are 9 and 128 , respectively. If necessary, you can save memory for program use by specifying stacks=0,0 ; this may or may not cause a program crash. You can specify stacks=8,512 to allocate plenty of stack space if you suspect that interrupt handlers are causing DOS crashes. SWITCHES=/K makes MS-DOS programs treat the keyboard as a "conventional" 96-key keyboard even if it uses the extended 102+ key layout. If you use this switch and also load ansi.sys , specify /k after ansi.sys as well. The following items are permitted in CONFIG.NT for compatibility with historical CONFIG.SYS settings but have no effect in Windows XP:
AUTOEXEC.NTAUTOEXEC.NT serves the same purpose AUTOEXEC.BAT did on MS-DOS systems: It is a batch file that lets you run programs that set up the command environment before you begin working. The default version of AUTOEXEC.NT installed with Windows is located in \windows\system32 and contains the following commands: lh %SystemRoot%\system32\mscdexnt.exe lh %SystemRoot%\system32\redir lh %SystemRoot%\system32\dosx SET BLASTER=A220 I5 D1 P330 T3 MSCDEXNT provides support for CD-ROM drives , REDIR is the network interface, DOSX provides upper-memory support (it serves the same purpose EMM386.EXE did on MS-DOS), and the SET command provides DOS programs with information about the simulated Sound Blaster sound hardware. No matter what kind of sound system your computer has, MS-DOS programs "see" a Sound Blastercompatible card (although the emulation is less than perfect). In addition, if you've installed the Client for Novell Networks, AUTOEXEC.NT will also run nw16.exe and vwipxspx.exe , which give DOS applications access to the Novell application programming interface (API). You can load other programs and set environment variables in AUTOEXEC.NT , but remember that they will be loaded every time you run an MS-DOS program. If you need particular terminate-and-stay-resident programs only for some MS-DOS applications, set up a customized AUTOEXEC file just for those applications. Tip One program that's handy to add to AUTOEXEC.NT is doskey , which gives command.com the same editing commands as those provided by cmd.exe , and in addition, it lets you define abbreviated commands called aliases . To read about this program, start the Help and Support Center and search for "doskey." MS-DOS Environment VariablesIn MS-DOS, memory is a limited resource, and MS-DOS is particularly stingy with environment variable space. If you need to define more than a dozen or so environment variables in any MS-DOSstyle batch files, you'll probably need to extend the amount of space allocated to environment variables either on the Properties dialog box of an associated shortcut or in a shell= command in a CONFIG.NT file. These techniques were described earlier in this appendix. When you first start an MS-DOS program or command.com , ntvdm inherits the default Windows environment, but with the following changes:
|