DOS Window cmd.exe prompt

by Wayne Maples [Published on 20 April 2004 / Last Updated on 20 April 2004]

If you have a unix background or have a DOS background, you know how valuable the command-shell can be for administrators. I work in that dark place constantly and get harrassed by the youngsters that only know the Windows GUI. But its amazing how little use the GUI is when one needs to perform the same task for 100 accounts or 30 servers. It gets really wearing to use the GUI. Unix has a very full-featured ability to customize the prompt. The DOS emulator in NT, W2K and XP has useful features also. My favorite is the UNC name that will display the UNC name of the server you have a net use to. My standard prompt is now:

prompt $m$_$p$g

This keeps me from getting confused when I am coping files from server to server. For example, lets say I have a network drive P: mapped to \\serverp\shareA and a network drive Q: mapped to \\serverq\shareA, then the prompt when I am on drive P: displays as

\\serverp\shareA
P:\

and if I change to drive Q:

\\serverq\shareA
Q:\

Its great if you have drive letters for multiple remote servers opened. Much easier than trying to remember what drive letler Q:, R:, S:, T:, etc are mapped to. For the options available to the prompt command, issue the command help prompt :

PROMPT [text]

  text    Specifies a new command prompt.

Prompt can be made up of normal characters and the following special codes:

  $A   & (Ampersand)
  $B   | (pipe)
  $C   ( (Left parenthesis)
  $D   Current date
  $E   Escape code (ASCII code 27)
  $F   ) (Right parenthesis)
  $G   > (greater-than sign)
  $H   Backspace (erases previous character)
  $L   < (less-than sign)
  $N   Current drive
  $P   Current drive and path
  $Q   = (equal sign)
  $S     (space)
  $T   Current time
  $V   Windows XP version number
  $_   Carriage return and linefeed
  $$   $ (dollar sign)

If Command Extensions are enabled the PROMPT command supports
the following additional formatting characters:

  $+   zero or more plus sign (+) characters depending upon the
       depth of the PUSHD directory stack, one character for each
       level pushed.

  $M   Displays the remote name associated with the current drive
       letter or the empty string if current drive is not a network
       drive.

If this doesn't work for you, the command extensions may have been disabled. To temporarily enable the extensions:

cmd /x enables command extensions for this cmd session

If the extensions now work, you can permanently enable them using the Windows 2000 / Windows XP registry hack:

Enable / Disable Command (cmd.exe) prompt extensions

CMD.exe looks like a normal DOS prompt but it isn't DOS. Nor is it a DOS emulator. It's a native 32-bit application that has little to do with DOS except for the user interface and its shell supporting similar commands. From a unix perspective, cmd.exe is NT/W2K/XP's native shell. Using it, you can run shell commands or any programs. Some of the commands are the same as in DOS. Run Cmd.exe and you'll see the version information displayed in the first two lines:


Microsoft(R) Windows NT(TM)
(C) Copyright 1985-1996 Microsoft Corp.

Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.
Command.com is available under NT/W2K/XP and is another shell. When you run it, you'll see :


Microsoft(R) Windows NT DOS
(C) Copyright Microsoft Corp 1990-1996.
Note it says NT DOS. Its there to run 16-bit DOS programs. If an old program will not run under the cmd.exe shell, try running it under Command.com. Note as a 16-bit program, Command.com doesn't support long filenames.

Featured Links