How do I change the command-line prompt in Windows?

WindowsCmdPrompt

Windows Problem Overview


How do I change the command-line prompt into a console?

I've been looking in the console functions API, but I could not find anything for it.

Windows Solutions


Solution 1 - Windows

There's the PROMPT environment variable:

set PROMPT=$P$G

$P$G is the default value, giving you the usual C:\> type output. There are more format variables available here.

Solution 2 - Windows

Another possibility is to set the PROMPT environment variable (which in fact is what the PROMPT command does).

The advantage of this method is that you can easily set it system-wide and you don't need any scripts, edit the Windows Registry, etc. It will work for any console window no matter how you open it.

You can do it using two methods, GUI and command-line.

  1. GUI method

Simply press Win + Pause/Break (open System properties), click Advanced system settings, Environment variables and create a new user or system variable named PROMPT with the value set to whatever you want your prompt to look like. A system variable will set it for all users.

You can see it with pictures in this article.

  1. Command-line method

Another way to set the PROMPT environment variable permanently is to use the SETX command:

setx PROMPT <your-prompt-format>

If you want to set it for all users, just add the /M switch:

setx PROMPT /M <your-prompt-format>

3. Registry method

In fact, both previous methods just create a string value named PROMPT in the registry. For the current user, it's under the key HKEY_CURRENT_USER\Environment, and the system-wide one for all users under the key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment.


Check this page or other answers for details about the prompt format.

Note: it's possible that you will have to reboot your system (or possibly just sign out and in) for the changes to take effect. At least, you have to close and restart the application (console), so it loads the new or changed environment variable. If you can't do it for whatever reason, you can use the following method:

  1. Command-line method (temporary)

If you execute the PROMPT command, it will set the PROMPT environment variable in your local context, so it will take an effect immediately, but until the console is closed only. It's not stored permanently.

prompt <your-prompt-format>

Solution 3 - Windows

Using HELP:

C:\Windows-15:21:07.12> help PROMPT

Changes the cmd.exe command 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 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 the current drive is not a network
       drive.

Reference for "Command Extensions" (e.g. "Command Extensions are enabled by default.").

Solution 4 - Windows

Solution 5 - Windows

I found this article when searching for how to save the PROMPT command to always run when launching a command prompt. It works for any version of Windows.

  • Click the Start menu → Run.
  • From the Run dialog, type "regedit" without quotes and click OK.
  • From the Registry Editor, select HKEY_CURRENT_USER\Software\Microsoft\Command Processor.
  • If the AutoRun value is not present, right-click and click NewExpandable String Value. Name the value "AutoRun" without quotes.
  • Double-click the AutoRun value.
  • Under data, add "PROMPT" and the value you want to set for the prompt. In my example, "PROMPT $p$_$g".
  • Click OK.
  • Repeat the previous steps for HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor ​to apply the change to ALL users.
  • Close the Registry Editor.
  • Close the command prompt if open, and open it again. The prompt you entered is now employed.

Solution 6 - Windows

If you want to save changes, used

 setx prompt < format >

If you want to use it only one time

prompt < format >

Solution 7 - Windows

I use a batch file I call DOSbox.bat to set any environment strings I need, and I have a shortcut to it on my desktop. The command in the "Target:" box is C:\Windows\System32\cmd.exe /k DOSbox.bat. I have a Shortcut Key (Ctrl+Alt_D) to invoke it and the "Start in" set to my preferred directory. The shortcut also allows one to set the font, color, and location of the command window.

The contents of the batch file are currently:

@echo off
set dircmd=/ogne
prompt [$p]$_$g

The prompt shows the directory in brackets, and the ">" on a line by itself. This is useful for very long paths.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1243746View Question on Stackoverflow
Solution 1 - WindowsMarc BView Answer on Stackoverflow
Solution 2 - WindowsDavid Ferenczy RogožanView Answer on Stackoverflow
Solution 3 - WindowsDaveWView Answer on Stackoverflow
Solution 4 - WindowssdforView Answer on Stackoverflow
Solution 5 - WindowsCigarDougView Answer on Stackoverflow
Solution 6 - WindowswiotrekView Answer on Stackoverflow
Solution 7 - WindowsEngineerView Answer on Stackoverflow