Refresh Language Bar in Windows Vista/7 programatically

Im trying to configure the Language Bar (the language switcher in the systray which appears whan you have multiple input languages installed) for our users.

language bar

I can easily add new languages using regkeys below HKCU, but the problem is that the user has to relogin or reboot his computer to see the effect.

The keys i use (im writing them with an active setup) are in "HKEY_CURRENT_USER\Keyboard Layout\Preload" below that key are name/values of the type REG_SZ.

Usually there are already keys like "1"="0000407" "2"="0000409" which means the user has German and English keyboard layout installed, if i want to add, lets say italian, i would add the key "3"="0000410". after the next logoff/login the change is visible to the user.

now what i already tried is sending various windows messages, like WM_SETTINGCHANGE or the "RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters" command. but no usefull result so far.

im running out of ideas here, making hundreds of users logoff/logon wouldn't be so great :/

i also thought of automating mouseclicks (e.g. with autoit), but that usually causes more trouble than it does any good.


Solution 1:

You should not be doing this through registry editing, since our knowledge on that is quite limited, but use the mechanism supplied by Windows.

Microsoft has created Windows PowerShell as its main programming interface which allows access to virtually every functionality in Windows. Unfortunately, the family of PowerShell functions that pertains to language, International Settings Cmdlets, was only introduced for Windows 8/Server 2012 and is not available for Windows 7 or Vista.

Nevertheless, solutions do exist for Windows 7 or Vista, as described in the MSDN article:
Windows Vista Command Line Configuration of International Settings.

An example of using this technique is to be found in Configuring Regional and Language Options International Settings with command line automation, which basically uses a specially crafted xml file with the command:

control intl.cpl,, /f:"intlsettings.xml"

Below are listed some example xml files.

Change the current language

<gs:GlobalizationServices xmlns:gs="urn:longhornGlobalizationUnattend">
    <!--User List-->
    <gs:UserList>
        <gs:User UserID="Current"/>
    </gs:UserList>
    <!-- User Locale-->
    <gs:UserLocale>
        <gs:Locale Name="es-US" SetAsCurrent="true"/>
    </gs:UserLocale>
</gs:GlobalizationServices>

Add keyboard language

<gs:GlobalizationServices xmlns:gs="urn:longhornGlobalizationUnattend"> 
<gs:UserList>
<gs:User UserID="Current" CopySettingsToDefaultUserAcct="true" CopySettingsToSystemAcct="true"/></gs:UserList> 
<gs:InputPreferences> 
<gs:InputLanguageID Action="add" ID="0804:E0200804"/>
</gs:InputPreferences>
</gs:GlobalizationServices>

Remove keyboard language

<gs:GlobalizationServices xmlns:gs="urn:longhornGlobalizationUnattend"> 
<gs:UserList>
<gs:User UserID="Current" CopySettingsToDefaultUserAcct="true" CopySettingsToSystemAcct="true"/></gs:UserList> 
<gs:InputPreferences> 
<gs:InputLanguageID Action="remove" ID="0804:E0200804"/>
</gs:InputPreferences>
</gs:GlobalizationServices>

source