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

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.


Solution 1:

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:

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.

2. 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:

4. 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>