8

Some time now that I am using win7, it regularly messes my keyboard languages up, and I have to remotely add 3 keyboard languages, apply, and then remove them. So, I was wondering if there is a way to do it through a .bat file automatically(add 3 specific keyboard languages and then immediately remove them). However, I know almost nothing about .bat commands, so does anyone know if this is possible through a .bat file and if yes, what commands shall I use?

Thank you in advance, George.

gkatev
  • 81
  • 1
  • 2
  • 7
  • I don't know if there is a command line interface to control keyboard languages - but a keyboard macro using `a macro program` could be a solution. `AutoIt` is another tool which can automate keyboard and mouse movements. – foxidrive May 12 '13 at 14:58
  • not sure if this could help: http://jekkilekki.wordpress.com/2009/01/05/changing-os-languages-in-windows-xp/ – npocmaka May 12 '13 at 15:50

5 Answers5

8

It's possible.

http://blogs.msdn.com/b/shawnste/archive/2007/04/12/configuring-international-settings-from-the-command-line.aspx

http://msdn.microsoft.com/en-us/goglobal/bb964650#eyb

command line example to run the xml to add the keyboard language:

control intl.cpl,, /f:"%CD%\AddKeyboardLanguage.xml"

AddKeyboardLanguage.xml used to add Chinese keyboard language example:

<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:{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}{FA550B04-5AD7-411F-A5AC-CA038EC515D7}"/>

</gs:InputPreferences>
</gs:GlobalizationServices>

RemoveKeyboardLanguage.xml example:

<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:{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}{FA550B04-5AD7-411F-A5AC-CA038EC515D7}"/>

</gs:InputPreferences>
</gs:GlobalizationServices>

Batch file to add or remove the keyboard language (save as AddRemWindowsChinese.bat):

@echo off
if "%1"=="" echo ERROR: Missing [add]/[remove] parameter & goto :USAGE
if /i %1==add (
    echo control intl.cpl,, /f:"%CD%\AddWindowsChinese.xml"
    control intl.cpl,, /f:"%CD%\AddWindowsChinese.xml"
    IF ERRORLEVEL 1 echo An error occured ! && goto :ERROR
)
if /i %1==remove (
echo %CD%
    echo control intl.cpl,, /f:"%CD%\RemoveWindowsChinese.xml"
    control intl.cpl,, /f:"%CD%\RemoveWindowsChinese.xml"
    IF ERRORLEVEL 1 echo An error occured ! && goto :ERROR
)
GOTO :END

:USAGE
echo.
echo USAGE:
echo AddRemWindowsChinese.bat [add ^| remove]
echo.
pause
goto :END

:ERROR

:END
Ying
  • 361
  • 4
  • 8
  • 1
    For me it works very well on Win7. I wasn't replying to you specifically, but since I needed the same solution and stumbled upon your question during my research, I thought it might be useful for other people in the future. – Ying Aug 22 '13 at 16:26
  • Just for the records: Why do you add `` into your .xml file? – PeterCo Feb 15 '18 at 11:16
  • I think it can be removed. It's just a comment. – Ying Feb 17 '18 at 20:02
  • Removed the comment per PeterCo feedback. – Ying Mar 10 '21 at 16:35
5

I also have been experiencing the same problem - en-US is added automatically, and I had to add en-US and then remove it in order to get rid of the layout. Even with the batch file, I found that you cannot just remove it, you have to first add the layout (even if it is showing on the keyboard layout list) to be able to remove it just like when you do it manually.

Hence, the Remove_en-US.xml file first adds the layout and then remove it:

<gs:GlobalizationServices xmlns:gs="urn:longhornGlobalizationUnattend">

    <!--User List-->
    <gs:UserList>
        <gs:User UserID="Current"/>
    </gs:UserList>

    <!--input preferences--> 
    <gs:InputPreferences>
        <!--add en-US keyboard input-->
        <gs:InputLanguageID Action="add" ID="0409:00000409"/>
        <!--remove en-US keyboard input-->
        <gs:InputLanguageID Action="remove" ID="0409:00000409"/>
    </gs:InputPreferences>

</gs:GlobalizationServices>

Remove_en-US.bat:

control intl.cpl,, /f:"%CD%\Add_en-US.xml"

Here, 0409 is the locale ID and 00000409 is the keyboard layout values. For the list of the locale ID:keyboard layout value see https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-8.1-and-8/hh825682(v=win.10).

joon
  • 3,899
  • 1
  • 40
  • 53
3

Using @Ying tips/link... I made a pt.xml file:

<gs:GlobalizationServices xmlns:gs="urn:longhornGlobalizationUnattend">

    <!--User List-->
    <gs:UserList>
        <gs:User UserID="Current"/>
    </gs:UserList>

    <!--input preferences--> 
    <gs:InputPreferences>
        <!--add pt-BR keyboard input and set as default-->
        <gs:InputLanguageID Action="add" ID="0416:00010416" Default="true"/>
    </gs:InputPreferences>

</gs:GlobalizationServices>

and then just create a .bat with this command inside:

control intl.cpl,, /f:"%CD%\pt.xml"

Double click it and it should work instantly!

Renato Parreira
  • 838
  • 1
  • 7
  • 23
  • Thank you very much for this concrete example. The critical hint is: You must **not** omit the double quote pair after `/f:` , otherwise, the `control.exe` command fails silently, -- at least so on Windows 7. – Jimm Chen Oct 15 '19 at 08:27
1

Keyboard languages are stored in the registry under HKEY_CURRENT_USER\Keyboard Layout You can use REG.EXE in Batch files to add/modify/remove registry keys. REG.EXE doesn't support remotely changing HKEY_CURRENT_USER registry keys so the file would have to be ran from the computer in question. We probably don't have to do that though. This is what I would do. When your computer is working as it should, Goto a CMD prompt by clicking the start button and typing CMD into the run box. From the CMD prompt, type:

  REG QUERY "HKCU\Keyboard Layout" /s

This will show you what the registry keys should look like when all is well. Now take a snapshot of that and store it in a file by typing:

  REG EXPORT "HKCU\Keyboard Layout" KeyboardLayout.reg

This will create the KeyboardLayout.reg file in whatever directory your CMD prompt says. I'm not sure why you would have to add 3 specific languages and then remove them to get back to working order but I have a feeling that just setting the registry back to the way it was when it worked would fix the problem. The next time it happens, remotely browse to the location of the KeyboardLayout.reg file and double click it. It will tell you the key has been updated and to click ok. See if that fixes it. If it doesn't, reboot that computer and see if it does then. If it still doesn't work, post back a comment and I'll tell you what I'd do next.

Matt Williamson
  • 6,947
  • 1
  • 23
  • 36
  • This cannot work. Installing a keyboard like "Chinese simplified" will require the installation of ~80 MB of stuff like fonts etc. A Registry key export and import cannot do this. – Thomas Weller Oct 07 '21 at 07:54
0

there is a powershell method as well. Here is simple batch to remove en-US and de-DE layouts

@echo off
for %%q in (en-US de-DE) do ^
powershell -c "$ll=Get-WinUserLanguageList; $ll.add('%%q'); Set-WinUserLanguageList $ll -force;" & ^
powershell -c "$ll=Get-WinUserLanguageList; $ll.remove(($ll |? LanguageTag -like '%%q')); Set-WinUserLanguageList $ll -force;"

first we have to add them, then remove. works fine for me.

anilech
  • 1,089
  • 8
  • 9