Skip to content

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

Closed

Description

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.

Activity

  1. ghost added
    Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting
    on Oct 23, 2021
  2. ghost added
    Needs-Tag-FixDoesn't match tag requirements
    on Oct 23, 2021
  3. j4james commented on Oct 24, 2021

    @j4james
    Collaborator

    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:

    reg.LoadDefaultFromRegistry();
    // 2. Read specific settings
    // Link is expecting the flags from the process to be in already, so apply that first
    settings.SetStartupFlags(pStartupSettings->GetStartupFlags());
    // We need to see if we were spawned from a link. If we were, we need to
    // call back into the shell to try to get all the console information from the link.
    ServiceLocator::LocateSystemConfigurationProvider()->GetSettingsFromLink(&settings, Title, &TitleLength, CurDir, AppName);
    // If we weren't started from a link, this will already be set.
    // If LoadLinkInfo couldn't find anything, it will remove the flag so we can dig in the registry.
    if (!(settings.IsStartupTitleIsLinkNameSet()))
    {
    reg.LoadFromRegistry(Title);
    }

    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:

    void SystemConfigurationProvider::GetSettingsFromLink(
    _Inout_ Settings* pLinkSettings,
    _Inout_updates_bytes_(*pdwTitleLength) LPWSTR pwszTitle,
    _Inout_ PDWORD pdwTitleLength,
    _In_ PCWSTR pwszCurrDir,
    _In_ PCWSTR pwszAppName)
    {
    CONSOLE_INFORMATION& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
    WCHAR wszLinkTarget[MAX_PATH] = { 0 };
    WCHAR wszIconLocation[MAX_PATH] = { 0 };
    int iIconIndex = 0;
    pLinkSettings->SetCodePage(ServiceLocator::LocateGlobals().uiOEMCP);

    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.

  4. j4james commented on Oct 24, 2021

    @j4james
    Collaborator

    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:

    // Use the launch arguments to check if we're going to be started in pseudoconsole mode.
    // If we are, we don't want to load any user settings, because that could
    // result in some strange rendering results in the end terminal.
    // Use the launch args because the VtIo hasn't been initialized yet.
    if (!launchArgs.InConptyMode())
    {
    // 3. Read the default registry values.
    Registry reg(&settings);

  5. eryksun commented on Oct 24, 2021

    @eryksun

    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.

  6. j4james commented on Oct 24, 2021

    @j4james
    Collaborator

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

  7. vefatica commented on Oct 24, 2021

    @vefatica
    Author

    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, James Holderness (@j4james), that's not currently possible. The user should have some say ... yes/no?

  8. j4james commented on Oct 24, 2021

    @j4james
    Collaborator

    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.

  9. vefatica commented on Oct 24, 2021

    @vefatica
    Author

    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
    
  10. vefatica commented on Oct 24, 2021

    @vefatica
    Author

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

    image

  11. j4james commented on Oct 24, 2021

    @j4james
    Collaborator

    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

  12. vefatica commented on Oct 24, 2021

    @vefatica
    Author

    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.

  13. zadjii-msft commented on Nov 3, 2021

    @zadjii-msft
    Member

    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.

  14. carlos-zamora commented on Aug 9, 2023

    @carlos-zamora

    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.

  15. microsoft-github-policy-service commented on Aug 9, 2023

    @microsoft-github-policy-service
    Contributor

    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!

  16. added
    Resolution-DuplicateThere's another issue on the tracker that's pretty much the same thing.
    and removed
    Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting
    Needs-Tag-FixDoesn't match tag requirements
    on Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-QuestionFor questions or discussionProduct-ConptyFor console issues specifically related to conptyResolution-DuplicateThere's another issue on the tracker that's pretty much the same thing.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions