Quantcast
Channel: Programming – Xinyustudio
Viewing all articles
Browse latest Browse all 284

C#: programmatically get and set non-unicode languages for windows OS

$
0
0

We know that we can use English version of Windows and at the same time to display non-unicode texts such as Chinese and Japanese etc. The procedures are as follows:

Control Panel > Region > Administrative Tab, and then “Change system locale” button.

image

image

But how do this using C#? This post offers my initial attempt to accomplish this task.

The settings for this non-unicode languages are kept in registry:

image

The value for the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\Language “default” value is the hex code (LCID Hexadecimal) of the system’s non-unicode language, for commonly used LCID code, click here or this link from Microsoft for details.

For instance, “0804” is the hex LCID code for “Chinese – People’s Republic of China”.

To get or change the non-unicode languages for windows OS, we can edit this registry key value using C#, and the code snippet is like this:

image

Similarly, the code to set a specific language is then straightforward:

image

But wait, this is not all! If you calling the function:

SetSystemNonUnicodeLanguage(CultureInfo.GetCultureInfo(“zh-HK”));

you will find there is no error, no exception, and using regedit.exe shows the registry key is also changed correctly, but, if you using control panel region settings to have a look, you will find this is NOT updated. The reason is, you have to restart to make this setting take effect!

So, I created another function to restart the computer in code:

image

Great! Now call the RestartComputer() after calling SetSystemNonUnicodeLanguage(), it worked.

To save your effort, I have created a C# class SystemNonUnicodeLanguageEntry with static methods as below. Download this class here.image


Filed under: Dotnet/C#, Programming, Windows Tagged: .net, C#, control panel, get, language, Non unicode, region settings, set, system data and time

Viewing all articles
Browse latest Browse all 284

Trending Articles