Tip 25: Dress up your Command Prompt (Revisited)

Ever since the days of MS-DOS it has been possible to use the Prompt command to specify the command prompt that you see in a command console.

By default the prompt shows the current volume and directory, but Windows 2000 (like all Microsoft operating systems) gives you considerable control over the console prompt. For example, you can change the > symbol in the prompt to a different character or see the current time with the current path if you like.

If you’re like me and frequently work with remote shares from a console, you may want to display the network Universal Naming Convention (UNC) path as part of the prompt. This enables you to immediately see where you’re working, even if you’ve mapped that share to a local drive letter.! Perhaps you don’t recall that you’ve mapped drive P to \\ServerA\Public. With the UNC path in the prompt, you know instantly which share you’re using each time you change drives, as shown in the picture below.

To echo the UNC path for the current drive, use $m in the prompt. Because it is possible that the path could take up most of the command line, you may probably want to add a carriage return/line feed and present the command prompt on the following line.

The following syntax echoes the UNC path of the current path, inserts a carriage return/line feed, and displays the standard drive:path prompt:

prompt $m$_$p$g

Although you could enter the prompt command each time you open a command console, you may prefer to make the prompt change automatically for each console you open. To do that, create a system variable named "prompt" and set it to $m$_$p$g.

The following table presents the characters to specify in the prompt $<character> command.
Combinations of genuine text and prompt characters are also allowed, like in:

prompt Time = $t$_Date = $d$_$g

$ The $ character (dollar sign)
A The & character (Ampersand)
B The "pipe" character (¦)
C ( character (Left parenthesis)
D The current date
E Escape character (ASCII code X’1B’ = decimal 27)
F ) character (Right parenthesis)
G The > character
H Backspace (erases the previous character)
L The < character
M The network UNC path (or the empty string if current drive is not a network drive (see note))
N The default current drive
P The working directory of the default drive
S A space (leading spaces only!)
T The current time
V The version number of the command processor
_ A carriage return/line feed sequence
+ zero or more plus sign (+) characters depending upon the depth of the PUSHD directory stack, one character for each level pushed (see note)

Note The $m formatting character is supported by the PROMPT command, if the Windows 2000 / Windows XP Command Extensions are enabled. This is also true for the $+ formatting character.

To enable or disable the command prompt extension in Windows 2000 or Windows XP, use the following registry setting:

Hive: HKEY_CURRENT_USER
Key: Software\Microsoft\Command Processor
Name: EnableExtensions
Type: REG_DWORD
Value: 1 enable
Value: 0 disable

You can enable/disable the extensions for the command shell you are in by issuing the following commands:

cmd /y disables command extensions for this cmd session
cmd /x enables command extensions for this cmd session

Yet another reason for dressing up yoer command prompt is when you connect to multiple computers (e.g., by Telnet). You can configure the command prompt to display the name of the computer you’re connected to. The best way to do this is to configure the command processor to automatically run a prompt command at start-up to evaluate the %computername% environment variable.

To configure the prompt for everyone, use the following registry setting:

Hive: HKEY_LOCAL_MACHINE
Key: SOFTWARE\Microsoft\Command Processor
Name: AutoRun (Create it if it does not already exist)
Type: REG_SZ (String value)
Value: prompt [%computername%]$S$P$G

To configure the prompt only for the current user, use the following registry setting:

Hive: HKEY_CURRENT_USER
Key: Software\Microsoft\Command Processor
Name: AutoRun (Create it if it does not already exist)
Type: REG_SZ (String value)
Value: prompt [%computername%]$S$P$G

The change takes effect immediately. Your command prompt will now look like:

[SERVER01] c:\documents>

where "SERVER01" is the computer name. The registry setting passes the defined prompt command to the command processor when each command session starts. For an explanation of $S, $P and $G see the table listed before.

For other options, go to the command prompt and type:

prompt /?

to view the Help menu.