Changing the 'Region and Language' OS setting programmatically

Pooven picture Pooven · Mar 2, 2012 · Viewed 17.3k times · Source

I'd like to be able to change the Region and Language settings of the operating system (Windows 7) from a C# program. I'm not against executing command-line commands but I've only gotten as far as discovering how to launch the Region and Language dialog: control /name Microsoft.RegionAndLanguage

This is a language localisation problem where Controls like DateTimePicker can only use the Windows Region and Language settings (see here for details); however updating the operating system to conform to the application's language settings extends beyond this and is ultimately the desired goal.

Suggestions and/or workarounds would be appreciated.

Answer

Pooven picture Pooven · Mar 5, 2012

The only solution I managed to implement was to modify the registry. In Windows 7, when the language is changed, a new entry is added to the Registry in the subkey: HKEY_CURRENT_USER\Control Panel\Desktop. This key will contain the entry PreferredUILanguagesPending of type REG_MULTI_SZ and its value will determine the UI language. For the change to be applied the current user needs to log off and log in again. This can be done using the following code:

RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true);
string[] lang = {"en-ZA"};
key.SetValue("PreferredUILanguagesPending", lang, RegistryValueKind.MultiString);

The language pack needs to be installed before it can be set. For a list of language packs check here or here. When more than 1 language pack is installed option to change the UI language will appear in Control Panel > Region and Language > Keyboards and Languages > Display language.