HKCU\Console\CodePage ... does it do anything? #15666

Closed
opened 2026-01-31 04:44:56 +00:00 by claunia · 13 comments
Owner

Originally created by @vefatica on GitHub (Oct 23, 2021).

Microsoft Windows 10 Pro for Workstations
10.0.19043.1288 (2009, 21H1)

I thought that HKCU\Console\CodePage set the default output code page for consoles (and I'm pretty sure that, at least once upon a time, it did). But it does not now. Although I have

hkcu\console
  CodePage : REG_DWORD : 1252

all console apps which don't have another specification start with CP 437 (CP_OEMCP).

But if, for example, I have

hkcu\console\SystemRoot_system32_cmd.exe
    CodePage : REG_DWORD : 1252

then CMD will start with CP 1252.

Shouldn't HKCU\Console\CodePage be setting the default?

And (apparently unrelated to the above) how do I get all shells to use output code page 1252 when running in WindowsTerminal? They all seem to get 437.

Originally created by @vefatica on GitHub (Oct 23, 2021). Microsoft Windows 10 Pro for Workstations 10.0.19043.1288 (2009, 21H1) I thought that HKCU\Console\CodePage set the default output code page for consoles (and I'm pretty sure that, at least once upon a time, it did). But it does not now. Although I have ``` hkcu\console CodePage : REG_DWORD : 1252 ``` all console apps which don't have another specification start with CP 437 (CP_OEMCP). But if, for example, I have ``` hkcu\console\SystemRoot_system32_cmd.exe CodePage : REG_DWORD : 1252 ``` then CMD will start with CP 1252. Shouldn't HKCU\Console\CodePage be setting the default? And (apparently unrelated to the above) how do I get all shells to use output code page 1252 when running in WindowsTerminal? They all seem to get 437.
claunia added the Issue-QuestionResolution-DuplicateProduct-Conpty labels 2026-01-31 04:44:56 +00:00
Author
Owner

@j4james commented on GitHub (Oct 24, 2021):

I just happened to be looking at this area of the code recently, so I have a general idea of how it works, and this looks like a bug to me. The place that the settings are initialized at startup is in the SetUpConsole function. You can see the relevant bit here:

284257a383/src/host/srvinit.cpp (L174-L190)

Note that it loads the setting from the default registry area first, then potentially overrides that with settings in the shortcut link, and if there was no shortcut link, it'll look again in the registry for settings specific to the current executable.

The problem, though, is that the SystemConfigurationProvider::GetSettingsFromLink method always resets the codepage to the OEM value, regardless of whether a shortcut link is even involved, so any value read from the default registry area is guaranteed to be reset. See here:

fb597ed304/src/interactivity/win32/SystemConfigurationProvider.cpp (L58-L70)

I can't see any reason why that line is necessary, and removing it seems to fix the problem. But maybe one of the core devs will have access to the git history going further back and can see why it was added. It's possible there's a legitimate reason for it.

@j4james commented on GitHub (Oct 24, 2021): I just happened to be looking at this area of the code recently, so I have a general idea of how it works, and this looks like a bug to me. The place that the settings are initialized at startup is in the `SetUpConsole` function. You can see the relevant bit here: https://github.com/microsoft/terminal/blob/284257a38392c85a2f7d7ac7e77e20a05242ec64/src/host/srvinit.cpp#L174-L190 Note that it loads the setting from the default registry area first, then potentially overrides that with settings in the shortcut link, and if there was no shortcut link, it'll look again in the registry for settings specific to the current executable. The problem, though, is that the `SystemConfigurationProvider::GetSettingsFromLink` method always resets the codepage to the OEM value, regardless of whether a shortcut link is even involved, so any value read from the default registry area is guaranteed to be reset. See here: https://github.com/microsoft/terminal/blob/fb597ed304ec6eef245405c9652e9b8a029b821f/src/interactivity/win32/SystemConfigurationProvider.cpp#L58-L70 I can't see any reason why that line is necessary, and removing it seems to fix the problem. But maybe one of the core devs will have access to the git history going further back and can see why it was added. It's possible there's a legitimate reason for it.
Author
Owner

@j4james commented on GitHub (Oct 24, 2021):

And (apparently unrelated to the above) how do I get all shells to use output code page 1252 when running in WindowsTerminal? They all seem to get 437.

This seems to be by design. When conhost is started in a conpty session it deliberately doesn't initialize settings from the registry. See here:

284257a383/src/host/srvinit.cpp (L165-L172)

@j4james commented on GitHub (Oct 24, 2021): > And (apparently unrelated to the above) how do I get all shells to use output code page 1252 when running in WindowsTerminal? They all seem to get 437. This seems to be by design. When conhost is started in a conpty session it deliberately doesn't initialize settings from the registry. See here: https://github.com/microsoft/terminal/blob/284257a38392c85a2f7d7ac7e77e20a05242ec64/src/host/srvinit.cpp#L165-L172
Author
Owner

@eryksun commented on GitHub (Oct 24, 2021):

I can't see any reason why that line is necessary, and removing it seems to fix the problem. But maybe one of the core devs will have access to the git history going further back and can see why it was added.

If I recall correctly, the default "CodePage" setting was ignored in Windows 7. It definitely worked in Windows 2000, which I think was the first version of Windows that supported it. I verified this in Windows 2000 running in a VM.

When conhost is started in a conpty session it deliberately doesn't initialize settings from the registry.

A pair of functions could be added to the API to get and set the classic console settings that are applicable in the pseudoconsole context, such as "CodePage" and "NumberOfHistoryBuffers". For example: GetPseudoConsoleConfig(HPCON, PPSEUDO_CONSOLE_CONFIG) and SetPseudoConsoleConfig(HPCON, PPSEUDO_CONSOLE_CONFIG). The "Settings" tab in Windows Terminal could have a page to modify the default pseudoconsole settings (not the defaults in the registry), which each profile would be able to override.

@eryksun commented on GitHub (Oct 24, 2021): > I can't see any reason why that line is necessary, and removing it seems to fix the problem. But maybe one of the core devs will have access to the git history going further back and can see why it was added. If I recall correctly, the default "CodePage" setting was ignored in Windows 7. It definitely worked in Windows 2000, which I think was the first version of Windows that supported it. I verified this in Windows 2000 running in a VM. > When conhost is started in a conpty session it deliberately doesn't initialize settings from the registry. A pair of functions could be added to the API to get and set the classic console settings that are applicable in the pseudoconsole context, such as "CodePage" and "NumberOfHistoryBuffers". For example: `GetPseudoConsoleConfig(HPCON, PPSEUDO_CONSOLE_CONFIG)` and `SetPseudoConsoleConfig(HPCON, PPSEUDO_CONSOLE_CONFIG)`. The "Settings" tab in Windows Terminal could have a page to modify the default pseudoconsole settings (not the defaults in the registry), which each profile would be able to override.
Author
Owner

@j4james commented on GitHub (Oct 24, 2021):

If you're wanting a setting in Windows Terminal to specify the initial codepage for a profile, I think that is similar to what was requested in #9174 and/or #10870. It's also been discussed tangentially in https://github.com/microsoft/terminal/issues/10408#issuecomment-875149008.

@j4james commented on GitHub (Oct 24, 2021): If you're wanting a setting in Windows Terminal to specify the initial codepage for a profile, I think that is similar to what was requested in #9174 and/or #10870. It's also been discussed tangentially in https://github.com/microsoft/terminal/issues/10408#issuecomment-875149008.
Author
Owner

@vefatica commented on GitHub (Oct 24, 2021):

If you're wanting a setting in Windows Terminal to specify the initial codepage for a profile, I think that is similar to what was requested in #9174 and/or #10870. It's also been discussed tangentially in #10408 (comment).

I'd be happy with setting it for all profiles. If I read you correctly, @j4james, that's not currently possible. The user should have some say ... yes/no?

@vefatica commented on GitHub (Oct 24, 2021): > If you're wanting a setting in Windows Terminal to specify the initial codepage for a profile, I think that is similar to what was requested in #9174 and/or #10870. It's also been discussed tangentially in #10408 (comment). I'd be happy with setting it for all profiles. If I read you correctly, @j4james, that's not currently possible. The user should have **_some_** say ... yes/no?
Author
Owner

@j4james commented on GitHub (Oct 24, 2021):

Well the user does have some say. They can change the codepage with chcp. And if you're in a WSL shell you can at least change to something similar to 1252 with with echo -e '\e%@', and change back to UTF-8 with echo -e '\e%G'.

But Windows Terminal doesn't currently have any control over that (as far as I'm aware), because it's all handled in conhost. What gets passed to conpty (which is what Windows Terminal sees), is a simple stream of UTF-8 after everything has already been translated.

But if this is something you need to control from within Windows Terminal itself, I'd suggest upvoting #10870, which I believe is requesting the same thing. If you have a compelling use case for it, maybe explain what that is in a comment.

@j4james commented on GitHub (Oct 24, 2021): Well the user does have *some* say. They can change the codepage with `chcp`. And if you're in a WSL shell you can at least change to something similar to 1252 with with `echo -e '\e%@'`, and change back to UTF-8 with `echo -e '\e%G'`. But Windows Terminal doesn't currently have any control over that (as far as I'm aware), because it's all handled in conhost. What gets passed to conpty (which is what Windows Terminal sees), is a simple stream of UTF-8 after everything has already been translated. But if this is something you need to control from within Windows Terminal itself, I'd suggest upvoting #10870, which I believe is requesting the same thing. If you have a compelling use case for it, maybe explain what that is in a comment.
Author
Owner

@vefatica commented on GitHub (Oct 24, 2021):

When I started this thread, I was thinking Windows should be honoring the default code page setting. The user should have some across-the-board control in consoles and in WT. I upvoted #10870 but didn't leave a use case. Today's compelling reason is that I prefer the first (below) to the second. :-)

v:\> chcp 1252 & type V:\wmips.btm | findstr ZZZ
Active code page: 1252
:: rewrite YYYYMMDDHHMMSS.mmmmmm±ZZZ

v:\> chcp 437 & type V:\wmips.btm | findstr ZZZ
Active code page: 437
:: rewrite YYYYMMDDHHMMSS.mmmmmm▒ZZZ
@vefatica commented on GitHub (Oct 24, 2021): When I started this thread, I was thinking Windows should be honoring the default code page setting. The user should have some across-the-board control in consoles and in WT. I upvoted #10870 but didn't leave a use case. Today's compelling reason is that I prefer the first (below) to the second. :-) ``` v:\> chcp 1252 & type V:\wmips.btm | findstr ZZZ Active code page: 1252 :: rewrite YYYYMMDDHHMMSS.mmmmmm±ZZZ v:\> chcp 437 & type V:\wmips.btm | findstr ZZZ Active code page: 437 :: rewrite YYYYMMDDHHMMSS.mmmmmm▒ZZZ ```
Author
Owner

@vefatica commented on GitHub (Oct 24, 2021):

The pasted text in my last post looks peculiar in MSEGDE. It should look like this.

image

@vefatica commented on GitHub (Oct 24, 2021): The pasted text in my last post looks peculiar in MSEGDE. It should look like this. ![image](https://user-images.githubusercontent.com/61856645/138606701-65629d59-d2c1-48ed-a16c-c5a79e988576.png)
Author
Owner

@j4james commented on GitHub (Oct 24, 2021):

If you're using a cmd shell, you could just change the command line in your Windows Terminal profile to something like this: cmd.exe /k chcp 1252

@j4james commented on GitHub (Oct 24, 2021): If you're using a cmd shell, you could just change the command line in your Windows Terminal profile to something like this: ```cmd.exe /k chcp 1252```
Author
Owner

@vefatica commented on GitHub (Oct 24, 2021):

If you're using a cmd shell, you could just change the command line in your Windows Terminal profile to something like this: cmd.exe /k chcp 1252

... or use CMD's AutoRun file. I don't use CMD often. For any command interpreter, there are specific work-arounds.

@vefatica commented on GitHub (Oct 24, 2021): > If you're using a cmd shell, you could just change the command line in your Windows Terminal profile to something like this: cmd.exe /k chcp 1252 ... or use CMD's AutoRun file. I don't use CMD often. For any command interpreter, there are specific work-arounds.
Author
Owner

@zadjii-msft commented on GitHub (Nov 3, 2021):

You know, I thought our plan of record was to actually kinda go in the opposite direction, and have conpty force itself into utf-8 mode by default - #1802. Of course, we never really achieved consensus on that one, and I don't think any of us thought it was a terribly high-priority issue.

@zadjii-msft commented on GitHub (Nov 3, 2021): You know, I thought our plan of record was to actually kinda go in the opposite direction, and have conpty force itself into utf-8 mode by default - #1802. Of course, we never really achieved consensus on that one, and I don't think any of us thought it was a terribly high-priority issue.
Author
Owner

@carlos-zamora commented on GitHub (Aug 9, 2023):

Thanks for filing. We think the right solution to this is going to be allow the user to set the codepage in a compatibility page of the settings UI. This work spans several issues: #10870, #9174, #15678, and #1802. So we're going to mark this as a /dup of #1802, even though it's not necessarily the perfect solution to this question, but we'll use it to do the right thing.

@carlos-zamora commented on GitHub (Aug 9, 2023): Thanks for filing. We think the right solution to this is going to be allow the user to set the codepage in a compatibility page of the settings UI. This work spans several issues: #10870, #9174, #15678, and #1802. So we're going to mark this as a /dup of #1802, even though it's not necessarily the perfect solution to this question, but we'll use it to do the right thing.
Author
Owner

@microsoft-github-policy-service[bot] commented on GitHub (Aug 9, 2023):

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

@microsoft-github-policy-service[bot] commented on GitHub (Aug 9, 2023): Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#15666