如何在Windows 10和Windows 11中以编程方式禁用或启用“Beta: Use Unicode UTF-8 for worldwide language support”功能
如何在Windows 10和Windows 11中以编程方式禁用或启用“Beta: Use Unicode UTF-8 for worldwide language support”功能
我来帮你解决这个问题!你提到的这个「Beta: Use Unicode UTF-8 for worldwide language support」功能,是Windows为了统一全局字符编码、提升多语言环境兼容性推出的选项,平时可以通过打开intl.cpl(区域设置面板),在对应子窗口里勾选/取消复选框手动切换状态。要通过编程实现这个操作,核心是修改系统注册表,下面给你几种可行的方案:
方法一:用PowerShell快速修改(推荐)
这个功能的状态存储在注册表的HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage路径下,通过修改三个关键键值就能切换状态。注意必须以管理员权限运行PowerShell,否则会报错。
启用UTF-8全局支持
# 设置三个编码页键值为UTF-8的代码页编号65001 Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Nls\CodePage" -Name "ACP" -Value "65001" Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Nls\CodePage" -Name "OEMCP" -Value "65001" Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Nls\CodePage" -Name "MACCP" -Value "65001"
禁用UTF-8全局支持
如果是中文系统,把ACP和OEMCP的默认值改成936即可;英文系统用以下代码恢复默认:
# 恢复为英文系统默认编码页 Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Nls\CodePage" -Name "ACP" -Value "1252" Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Nls\CodePage" -Name "OEMCP" -Value "437" Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Nls\CodePage" -Name "MACCP" -Value "10000"
方法二:用原生编程语言实现(以C++为例)
如果你需要在桌面应用中集成这个功能,可以调用Windows注册表API来修改对应键值,示例代码如下:
#include <windows.h> #include <wchar.h> // enable为TRUE时启用UTF-8支持,FALSE时恢复默认 BOOL ToggleUTF8GlobalSupport(BOOL enable) { HKEY hRegKey; // 打开目标注册表项 LONG ret = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Nls\\CodePage", 0, KEY_SET_VALUE, &hRegKey); if (ret != ERROR_SUCCESS) { return FALSE; } // 定义要设置的键值对(中文系统默认值替换为L"936"即可) const wchar_t* acpVal = enable ? L"65001" : L"1252"; const wchar_t* oemcpVal = enable ? L"65001" : L"437"; const wchar_t* maccpVal = enable ? L"65001" : L"10000"; // 修改ACP键值 ret = RegSetValueExW(hRegKey, L"ACP", 0, REG_SZ, (const BYTE*)acpVal, (wcslen(acpVal) + 1) * sizeof(wchar_t)); if (ret != ERROR_SUCCESS) goto Cleanup; // 修改OEMCP键值 ret = RegSetValueExW(hRegKey, L"OEMCP", 0, REG_SZ, (const BYTE*)oemcpVal, (wcslen(oemcpVal) + 1) * sizeof(wchar_t)); if (ret != ERROR_SUCCESS) goto Cleanup; // 修改MACCP键值 ret = RegSetValueExW(hRegKey, L"MACCP", 0, REG_SZ, (const BYTE*)maccpVal, (wcslen(maccpVal) + 1) * sizeof(wchar_t)); Cleanup: RegCloseKey(hRegKey); return ret == ERROR_SUCCESS; }
重要提示:无论用哪种方法修改注册表后,必须重启系统才能让设置生效,这和手动修改复选框后的要求完全一致。
备注:内容来源于stack exchange,提问作者RokeJulianLockhart




