Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add/remove keyboard languages through .bat

Tags:

batch-file

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.

like image 919
gkatev Avatar asked May 12 '13 10:05

gkatev


2 Answers

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
like image 98
Ying Avatar answered Sep 21 '22 09:09

Ying


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://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-8.1-and-8/hh825682(v=win.10).

like image 31
joon Avatar answered Sep 21 '22 09:09

joon