'Programmatically change Keyboard Layout

I work in a Swiss company environment with de-CH as the standard keyboard-layout, while using a de-DE keyboard.

I'm able to change my keyboard settings manually to the preferred de-DE-layout, set it as standard and and assign a shortscut.

However: somehow my settings disappear after an arbitrary amount of time (might have something to do with updates the administrators run), so I have to repeat this every couple of days.

This suggests there's an easy way to change the keyboard-layout with Powershell in Win 8:

Set-WinUserLanguageList -LanguageList DE-DE

Sadly, I work with Win 7. Therefore, I get the following error message, which, as a Powershell-dummy, I interpret as a plain statement that the cmdlet doesn't exist in Win 7:

PS C:\Users\b036081> Set-WinUserLanguageList -LanguageList DE-DE
Set-WinUserLanguageList : The term 'Set-WinUserLanguageList' is not recognized as the name of a cmdlet, function, 
script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path 
is correct and try again.
At line:1 char:1
+ Set-WinUserLanguageList -LanguageList DE-DE
+ ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Set-WinUserLanguageList:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Now, is there another comparably simple way in Powershell? Or even in C++, C#, Batch, VB...

Thanks a lot!



Solution 1:[1]

While my system automatically resets to a de-CH layout IF i set any other language as default, I can still cycle to my prefered keyboard layout with ALT+SHIFT+1... just as long as i dont try to delete the non-used de-CH entry.

The Powershell approach doesn't seem to work with my system.

Solution 2:[2]

Use this command

powershell -command "Set-WinUserLanguageList -Force 'en-US'"

or

powershell -command "Set-WinUserLanguageList -Force 'fr-FR'"

Solution 3:[3]

I think you can change it in the registry.

There is a registry key under:

HKU:\.Default\Keyboard Layout\Preload\

Easily change it to the country code 00000407 - de-de in the registry, that should solve your problem.

But first you have to create a new PS-Drive, to "mount" the "HKEY_USERS" from registry.

$psdrive = New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS

Set-ItemProperty -Path "HKU:\.DEFAULT\Keyboard Layout\Preload\" -Name 1 -Value "00000407"

$psdrive | Remove-PSDrive

Solution 4:[4]

You can easily change current input language via .NET class, like this:

Add-Type -AssemblyName 'System.Windows.Forms'
[System.Windows.Forms.InputLanguage]::CurrentInputLanguage = [System.Windows.Forms.InputLanguage]::InstalledInputLanguages | ? { $_.Culture -eq 'ru-RU' }

Solution 5:[5]

Option 1: WinDefaultInputMethodOverride

You can override the default input method. The InputTip is the combination of language indetifier and keyboard identifier. (Default Input Profiles (Input Locales) in Windows)

Set-WinDefaultInputMethodOverride -InputTip '0409:00000409'

Option 2: Update Registry

For this, you have to be allowed to change the registry.

Set-ItemProperty -Path 'Registry::HKEY_USERS\.DEFAULT\Keyboard Layout\Preload\' -Name 1 -Value 00010409

Identifiers

A list of keyboard identifiers can be found on Keyboard Identifiers and Input Method Editors for Windows. In the registry you can find the ones available on your system. Language identifiers can be found on Available languages for Windows

Get-ChildItem -Path 'Registry::HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Keyboard Layouts\'

Solution 6:[6]

Run this below command in PowerShell window:

Set-WinDefaultInputMethodOverride -InputTip "0409:00000409"

This command sets the default input method override to English (United States) - US.

Another Input Profiles (Input Locales) here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Martin Dreher
Solution 2 Orkadia
Solution 3
Solution 4
Solution 5 conspicillatus
Solution 6 Feriman