Command Prompt [and PowerShell] multiple color settings - how to apply and export them from different versions / EXEs?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
DOSadnie
Posts: 143
Joined: 21 Jul 2022 15:12
Location: Coding Kindergarten

Command Prompt [and PowerShell] multiple color settings - how to apply and export them from different versions / EXEs?

#1 Post by DOSadnie » 02 Aug 2022 10:44

For the CMD [and also PowerShell] users of the Windows 7 and Windows 10 can define things like font size and its colors, by clicking the bar with the window's name and choosing Properties. But there are Matrix-like issues with this ability



#1] Where exactly are those settings stored in Windows 10?

I am just tired of setting them every time I install [from scratch] a new version of operating system. So maybe there are some config files that could be just copied / replaced? Or some Registry entries that could be exported to REG file, like in the case of Notepad; i.e. with a BAT file like

Code: Select all

reg export "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Notepad" "C:\Users\YOUR-USER-NAME\Documents\Notepad settings.reg"
?



#2] What's up with all those versions of cmd.exe?

I [vaguely] know why there is

C:\Windows\system32\cmd.exe

and also

C:\Windows\SysWOW64\cmd.exe

And because of that [for my own convenience] I made LNK files leading to them- plus [for further convenience] I also added to my freeware file manager FreeCommander some toolbar icon / shortcuts. And so I am able to execute CMD either from those LNK files or from toolbar icons - in either a normal mode or with Administrator privileges

But here comes the Matrix part: all in all, I am able to store seven [7!] different GUI settings, each showing itself according to a link / method chosen for running a cmd.exe file - but the Task Manager of operating system is always showing me that it is using always the same

C:\Windows\SysWOW64\cmd.exe

version. So how is it possible to have 7 configs for 2 executable files? [With PowerShell the Matrix stuff that is happening is similar, but as I have not dug in it thoroughly enough, I am unable to conclude that it is exactly the same]



#3] I have also noticed that every BAT file that I have after executing it simply ignores all of those color GUI settings that I made for those [7] various versions of Command Prompt

Trying to get to the root of this I have noticed [with the help of HIPS feature of the free COMODO] that when I execute any BAT file, it asks for access to

C:\Windows\System32\conhost.exe

And so I went to its location to run it. But as this file is invisible in FreeCommander as well as in Window Explorer [even when hidden files are set to be shown], I had to past in that path in the Address Bar of Window Explorer in order to execute that file. [Pasting that path in FreeCommander does not work. But that Matrix-like file can also be accessed with a help of 7-zip, which program does not see it but opens that path raveling

C:\Windows\System32\conhost.exe\.rsrc\version.txt

and also other files]


When conhost.exe is executed from a path, it opens yet another version of CMD. So one could think that this is it, that this is this location where default settings of Command Prompt are stored. And that by changing Properties of that one window all of the BAT files would be affected. Unfortunately as my test has shown, nothing changes - i.e. when I run this conhost.exe I get in it what I want [like changed colors], but when I run BAT files I still see a default scheme [of white on black]. And so in order to make my every BAT file color / font adjusted I would have to either manually add some script lines in them concerning their looks - or run them and then also manually adjust Properties in those regards. But then again the Matrix reveals itself. Because not only can I can adjust visuals for every of my BAT files by changing Properties for every single Command Prompt window that pops up - I can also override these Properties by running those BAT files via LNK shortcuts created for them [which I use on a daily basis as method of elevating some of my BATs to the Administrator level]



So coming back to questions:

A] How many different version of cmd.exe there really are in Windows 10?

B] Where are all these multiple settings stored. And can there be successfully exported and then imported on another machine?

C] Is PowerShell in regards to color settings handled also in the same way as Command Prompt?


[Currently I am using Windows 10 Enterprise 20H2 19042.746 x64]
Last edited by DOSadnie on 03 Jan 2023 06:19, edited 2 times in total.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Command Prompt [and PowerShell] multiple color settings - how to apply and export them from different versions / EXE

#2 Post by aGerman » 02 Aug 2022 11:18

A) Run

Code: Select all

where /r c:\windows cmd.exe
You'll probably find at least 4 where the cmd.exe files in subfolders of C:\Windows\WinSxS are just backups from Windows updates and not used (because they are not found in the paths listed in the %PATH% environment variable).
On a 64 bit OS like yours the 64 bit app C:\Windows\system32\cmd.exe is used if called from a 64 bit process, and the 32 bit app C:\Windows\syswow64\cmd.exe is used if called from a 32 bit process (in the WOW64 subsystem).

B) Settings like color and font are neither related to cmd.exe nor powershell.exe. Those are settings of the virtual terminal emulator. Refer to
https://github.com/microsoft/terminal/b ... s-terminal
If your VT emulator is conhost.exe you'll find the settings in the registry HKEY_CURRENT_USER\Console and subkeys. If your VT emulator is wt.exe (Windows Terminal) you'll find the settings in %localappdata%\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json (FWIW Windows Terminal ships with Win 11 and can be defined as default rather than conhost). 3rd party VT emulators have their settings stored somewhere else. So, there is no universal answer to this question.

C) Look at the powershell-related subkey of HKEY_CURRENT_USER\Console in case your question is about conhost. Although the explanations for B) apply here as well.

Steffen

DOSadnie
Posts: 143
Joined: 21 Jul 2022 15:12
Location: Coding Kindergarten

Re: Command Prompt [and PowerShell] multiple color settings - how to apply and export them from different versions / EXE

#3 Post by DOSadnie » 03 Aug 2022 08:50

I will look into this. But in the meantime:
DOSadnie wrote:
02 Aug 2022 10:44
[...]
I am able to store seven [7!] different GUI settings, each showing itself according to a link / method chosen for running a cmd.exe file
[...]
Maybe this has something to do with the fact that I am using 32-bit version of FreeCommander - while accessing 32-bit and 64-bit versions of CMD?

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Command Prompt [and PowerShell] multiple color settings - how to apply and export them from different versions / EXE

#4 Post by aGerman » 04 Aug 2022 15:04

Using a 32 bit app to replace the Windows Explorer on a 64 bit OS is kinda toxic. You have to keep in mind that almost every sytem tool started from there is running in the WOW64 subsystem. I don't actually get your question about those 7 settings. However, consider that FreeCommander is the culprit if you would be able to reduce this number by using Windows Explorer only.

Steffen

DOSadnie
Posts: 143
Joined: 21 Jul 2022 15:12
Location: Coding Kindergarten

Re: Command Prompt [and PowerShell] multiple color settings - how to apply and export them from different versions / EXE

#5 Post by DOSadnie » 03 Jan 2023 09:57

aGerman wrote:
04 Aug 2022 15:04
Using a 32 bit app to replace the Windows Explorer on a 64 bit OS is kinda toxic
Yes, as times goes by I stumble upon more and more issues that, when investigated on various forums, come down to the issue of using 32-bit version of FreeCommander; which for me has replaced Windows Explorer and Desktop feature in 99% and took over many shortcuts from my Taskbar and allowed me for creating a magnitude more of them within it. Also some niche / obsolete programs that I use fall into that pit hole of toxic
aGerman wrote:
04 Aug 2022 15:04
[...]
However, consider that FreeCommander is the culprit if you would be able to reduce this number by using Windows Explorer only.
I think that once you start using any good file manager for daily work [and not just some task like uploading to an FTP server] there is no going back

And to my limited knowledge, but based on my vast experience and my understanding of your explanations about consoles, this issue of multiple versions of CMD and PowerShell has nothing to do with me using FreeCommander - FC just happens to utilize whatever Windows gives it access to

As for
aGerman wrote:
04 Aug 2022 15:04
those 7 settings
It seems that all I have to do to create 8th, 9th and so on is to create another LNK file leading to the very same BAT file - as they all get default settings applied to them, which then can be changed

DOSadnie
Posts: 143
Joined: 21 Jul 2022 15:12
Location: Coding Kindergarten

Re: Command Prompt [and PowerShell] multiple color settings - how to apply and export them from different versions / EXE

#6 Post by DOSadnie » 04 Jan 2023 08:36

And coming back to
aGerman wrote:
02 Aug 2022 11:18
[...]
B) Settings like color and font are neither related to cmd.exe nor powershell.exe. Those are settings of the virtual terminal emulator. Refer to
https://github.com/microsoft/terminal/b ... s-terminal
which is:

>>
What's the difference between a shell and a terminal?

I think there might be a bit of a misunderstanding here - there are two different kinds of applications we're talking about here:

● shell applications, like cmd.exe, powershell, zsh, etc. These are text-only applications that emit streams of characters. They don't care at all about how they're eventually rendered to the user. These are also sometimes referred to as "commandline client" applications.
● terminal applications, like the Windows Terminal, gnome-terminal, xterm, iterm2, hyper. These are graphical applications that can be used to render the output of commandline clients.

On Windows, if you just run cmd.exe directly, the OS will create an instance of conhost.exe as the terminal for cmd.exe. The same thing happens for powershell.exe, the system will create a new conhost window for any client that's not already connected to a terminal of some sort. This has lead to an enormous amount of confusion for people thinking that a conhost window is actually a "cmd window". cmd can't have a window, it's just a commandline application. Its window is always some other terminal.

Any terminal can run any commandline client application. So you can use the Windows Terminal to run whatever shell you want. I use mine for both cmd and powershell, and also WSL:

Image

It's not the Terminal's responsibility to remember the commands executed by a commandline client. That's the responsibility of the shell. How would the terminal remember commands executed by something like emacs or vim? Those are both applications where the user is typing input and hitting enter, like they would at a cmd prompt, but without something that resembles a command history.

<<

The above explanation by @zadjii-msft makes things much clearer. [Please do not ban me from this forum for that long citation of content from another - I just want to save this whole topic as one file and put it my very own help files concerning batch scripting, for further reference]
aGerman wrote:
02 Aug 2022 11:18
If your VT emulator is conhost.exe you'll find the settings in the registry HKEY_CURRENT_USER\Console and subkeys. If your VT emulator is
[...]
C) Look at the powershell-related subkey of HKEY_CURRENT_USER\Console in case your question is about conhost. Although the explanations for B) apply here as well.
Yes. After testing it seems to be as simple as that: a BATfile like this

Code: Select all

reg export "HKEY_CURRENT_USER\Console" "C:\Users\YOUR-USER-NAME\Documents\CMD _ PowerShell Settings.reg"
will export settings of most of versions which I encounter through my Windows. And as the remaining ones I do not really use, thus I will not waste time trying to pin point them in the Registry by means of changing their settings and then looking for such new values; because from previous such endeavors of such kind I know I can bury myself with dozens of places to verify them with mundane tests

In other words: its good enough - case closed

And of course thank you very much for your help

DOSadnie
Posts: 143
Joined: 21 Jul 2022 15:12
Location: Coding Kindergarten

Re: Command Prompt [and PowerShell] multiple color settings - how to apply and export them from different versions / EXE

#7 Post by DOSadnie » 06 Jan 2023 06:55

aGerman wrote:
02 Aug 2022 11:18
[...]
HKEY_CURRENT_USER\Console
[...]
DOSadnie wrote:
04 Jan 2023 08:36
[...]
the remaining ones I do not really use, thus I will not waste time trying to pin point them in the Registry
[...]
After all it was very quick easy and to do [by the means of exporting the whole Registry and just using CTRL + F with system32_cmd.exe] - as this seems to be the place, where the UI settings for remaining versions are stored on my OS:

HKEY_USERS\S-1-5-21-3797103458-798797042-3558267449-1001\Console

Post Reply