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

8

69

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.

Waterloo answered 19/8, 2012 at 17:12 Comment(6)
Do you mean programmatically ? If not, just use prompt _identifier_ in a cmd window.Continually
I want not use an environment variable; I just want to do it through its API, if it's possible.Waterloo
AFAIK prompt is not a property of console, but rather of cmd interpreterPrecocity
The command interpreter doesn't have an API. The only way to change the prompt is using the environment variable.Kailyard
@Continually what if you want to do it programmatically?Argentiferous
About prompt _identifier_: prompt | Microsoft DocsSyllable
I
97

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.

Icj answered 19/8, 2012 at 17:18 Comment(1)
Very useful prompt when you get deep into the directory structure: prompt $P$_$G. Once set with the prompt command, it is set for future cmd shell windows.Stigmatism
V
46

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>
Vocation answered 23/9, 2015 at 17:15 Comment(5)
Most complete and accurate answer.Homologue
FYI, even though you are not directly modifying the registry, that's how setx saves persistent environment variables. They are saved to "HKEY_CURRENT_USER\Environment" for the current user, or "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" for all users (with the /M flag).Diatessaron
@Diatessaron Well, that's exactly what I'm describing in my answer under the section 2, isn't it? Or I'm missing your point.Stereoscope
I must be crazy. I thought I was commenting on changing the prompt without modifying the registry. Now I don't see what I thought I was referring to.Diatessaron
But what if I want to change the color of the current prompt, whatever it may be? Say I want to keep Anaconda Prompt's format which looks like (base) E:\VSCodeProjects>. I can temporarily change its color by doing set "PROMPT=$e[44m%PROMPT%$e[0m" but it is only temporary. I guess it is not okay to set this to prompt variable permanently because it changes all the time based on previous %PROMPT%.Butlery
M
23

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.").

Moot answered 14/7, 2015 at 19:25 Comment(0)
S
8

The command is:

prompt yourPrompt

The full list of options is at Microsoft Windows XP - Prompt

Seabolt answered 19/6, 2014 at 19:47 Comment(1)
@narF, link fixed via WayBackMachine... be the change you want to see in the world :)Adiathermancy
S
6

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.
Sciential answered 13/8, 2014 at 16:0 Comment(1)
If one wants to have the setting permanent, this is one of the right answers!Utrecht
W
1

If you want to save changes, used

 setx prompt < format >

If you want to use it only one time

prompt < format >
Whitebeam answered 15/4, 2020 at 9:34 Comment(0)
D
1

Thanks years i didn't changed my prompt.

here a 2 lines prompt with path on first line some can be long and with colors, using this with black theme

set prompt=$E[36m%username%$E[31m@$E[36m%computername%$E[0m$G$P$_$E[32m$D$E[0m-$E[33m$T$E[0m$G

  • reset color (white for me cause of black theme) : $E[0m
  • red : $E[31m
  • green : $E[32m
  • orange : $E[33m
  • blue : $E[34m
  • purple / violet : $E[35m
  • light blue : $E[36m

For more color / back ground can have a look to

in power shell can type it for you cession

function prompt {"PS $([char]0x1b)[36m$env:username$([char]0x1b)[31m@$([char]0x1b)[36m$env:computername$([char]0x1b)[0m $($PWD.ProviderPath)`n$([char]0x1b)[32m$(Get-Date)$([char]0x1b)[0m($NestedPromptLevel) >"}

To get it permanent, you will need to authorize scripts so up to you. Have a look here

for me Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser was enough

Powershell prompt

Power shell profils

some more here

Delamination answered 13/4, 2024 at 12:23 Comment(0)
D
0

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.

Dukas answered 19/6, 2014 at 20:2 Comment(3)
This is not very universal. User usually need to execute console in a directory, where he's currently working, e.g. in file manager. So I navigate to target directory in Total Commander and using it's command prompt I execute cmd. Your method won't work in this workflow. AutoRun in registry or simple setting PROMPT environment variable as I described in my answer will work no matter how you execute the console.Stereoscope
There's no cmd box on a directory in File Manager. Total Commander is not very universal. :pDukas
I don't know, what you mean by File Manager. But in Windows Explorer just right-click on any directory with Shift key pressed and click on "Open command window here". This works everywhere where you can open directory context menu. Also I have no clue what you mean by "Total Commander is not very universal". It's much more universal than Windows Explorer, which is not very useful for real work.Stereoscope

© 2022 - 2025 — McMap. All rights reserved.