Disassembler0 / Win10-Initial-Setup-Script

PowerShell script for automation of routine tasks done after fresh installations of Windows 10 / Server 2016 / Server 2019
MIT License
4.69k stars 1.08k forks source link

Add support for enabling UTF-8 support globally #252

Closed abdusco closed 4 years ago

abdusco commented 5 years ago

Windows by default doesn't support printing utf-8 characters in console applications. One way to solve this is to change ansi code page, but a better way is to enable it from settings, which solves the problem altogether: image

I'm not sure how enabling this changes registry, but is it possible to add support for this setting?

r-chvrt commented 5 years ago

This might help you : https://superuser.com/questions/269818/change-default-code-page-of-windows-console-to-utf-8

abdusco commented 5 years ago

@c-rilaun I know that already. I've found this setting from the link you posted. The reason I've created this issue is to see if it can be automated using a script.

r-chvrt commented 5 years ago

@abdusco If you know that already, you have your answer. There is all you need to know for this settings :

To change the codepage for the console only, do the following: -Start -> Run -> regedit -Go to [HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\Autorun] -Change the value to chcp 65001

Changing HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage\OEMCP value to 65001 appear to make the system unable to boot in my case.

Personally, I don't like changing the registry. This can cause a lot of problems. I created a batch file:

@ECHO OFF
REM change CHCP to UTF-8
CHCP 65001
CLS

Quick edit : Some settings are uncommon, like this one and the edit of Windows value by regedit could be dangerous (especially for this one). So i don't think if a dangerous feature, uncommon, will be added to the script. But you can fork the git repo and make your custom tool. (Don't hesitate to correct my poor english)

Disassembler0 commented 4 years ago

This would probably cause more problems than it would solve. Even if the tweak would exist,there is no clear way how to revert it as the original values depend on the default locale/language of the OS. I.e. de_DE or ru_RE have different values than en_US. Moreover, it also affects old GUI (non-unicode) applications, which may lead to unexpected behavior even though the apps will appear to run and display normally. (I've had some fun with this on one ancient central european accounting system.)

So if you need it really just for console apps, then the solutions found by @c-rilaun seem the best. Either chcp 65001 for particular script/session or the Command Processor\Autorun key for all cmd sessions.

If you'd really want to achieve the same as the checkbox does, you can create a custom tweak with following

Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\Nls\CodePage" -Name "ACP" -Type String -Value 65001
Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\Nls\CodePage" -Name "OEMCP" -Type String -Value 65001
Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\Nls\CodePage" -Name "MACCP" -Type String -Value 65001

Notice that the values are strings and not dwords as one might expect. The person asking the question on SuperUser claims they've had problems with boot on Windows 7 after setting the OEMCP value, which may have been caused by using the wrong type. I have tested it just now on Win10 with the PS commands above and it booted normally.

tomasz1986 commented 4 years ago

The person asking the question on SuperUser claims they've had problems with boot on Windows 7 after setting the OEMCP value, which may have been caused by using the wrong type. I have tested it just now on Win10 with the PS commands above and it booted normally.

I do not know whether anyone will read this, but I just wanted to say that setting OEMCP to 65001 does break Windows 7, so something must have changed in the code in the meantime between 7 and 10.

image