Windows 7 - Change Region and Language settings using a script

OS: Windows 7 64-bit

I have a machine that has had its "Region and Language" settings all set to "Canada". What I need to do is change all those settings to revert back to the default of "United States". Additionally, I want to create a script to do this, as I expect to run into more machines with this issue. I don't want to have to change settings through the GUI on every machine.

I need to do these actions on these tabs:

Region and Language (Format)-
I need "Format" changed to "English (United States)"

Region and Language (Location)-
I need "Current Location" set to "United States"

Region and Language - Text Services and Input Language (General)-
I need to delete all keyboard languages except for "English (United States) - US"

Region and Language (Administrative)-
Here I believe that "non-Unicode programs" will also have to be set to "English (United States)"

(I have screenshots but I do not have the reputation required to post them.)

So far I have found this document from Microsoft that demonstrates an XML file that can be created to modify the settings above

The problem is that the only XML example from the link that appears to be working properly is the one for adding and setting a keyboard language as default. I have tried some of the other examples but they do not appear to be working. Here's a working example:

<gs:GlobalizationServices xmlns:gs="urn:longhornGlobalizationUnattend">
<!--User List-->
<gs:UserList>
<gs:User UserID="Current"/>
</gs:UserList>
<!--input preferences-->
<gs:InputPreferences>
<!--en-US-->
<gs:InputLanguageID Action="add" ID="0409:00000409" Default="true"/>
<!--en-CANADA-->
<gs:InputLanguageID Action="remove" ID="1009:00001009"/>
</gs:InputPreferences>
</gs:GlobalizationServices>

The code above will add in the United States keyboard language if it doesn't exist and then set it as default, but unfortunately I can't get it to delete the Canadian keyboard language.

Is there a method to programatically change all these settings? Am I overlooking something obvious?


Solution 1:

I was able to come up with a solution to my problem!
There are a few things I learned.

In the "ID", the portion of the number in front of the colon ("1009") represents the Region Keyboard ie English(Canada). The number after the colon ("00001009") is the actual language installed for that keyboard. "00001009" will actually target the "Canada French" under the Region keyboard of English(Canada)

Another thing that I learned is that the region codes on the MS site were not displayed properly, which is why I wasn't able to change the "Locale" properly. This link contains the values you need to use when changing the "Locale". US is GeoID=244

The other thing I ended up having to do was to create two different XML files and run them one after the other. For some reason, removing the English(Canada) keyboard and all of it's sublanguages then adding the English(US) keyboard in the same script was producing an error that was stopping the XML file from applying properly. I had to do the removal of the keyboards (I left the Format and Locale change) in one XML file and the adding of the US keyboard in another XML file.

Anyway, for anyone interested I will post my final XML files below. To run them I used the following commands in a batch file.

control intl.cpl,, /f:"<path_to_file>"

(there is a space after the second comma)

First script to remove keyboards, change Format, and change Locale
Pay special attention to how the "ID" values are done, it illustrates what I was trying to explain above!

    <gs:User UserID="Current"/>

    </gs:UserList>

    <!--input preferences - Keyboard languages-->

    <gs:InputPreferences>

    <!--Beginning of en-CANADA-->

    <!--Remove Canada French from under keyboard English(Canada)-->
    <gs:InputLanguageID Action="remove" ID="1009:00001009"/>
    <!--Remove Canadian MultiLingual Standard from under keyboard English(Canada)-->
    <gs:InputLanguageID Action="remove" ID="1009:00011009"/>
    <!--Remove US from under keyboard English(Canada)-->
    <gs:InputLanguageID Action="remove" ID="1009:00000409"/>

    <!--Beginning of en-US-->
    <!--Add keyboard US(English)-->
    <!--Please note that the command below was moved into another XML file. Reason being, it was causing an error-->
    <!--that would stop the US keyboard from being installed properly.-->
    <!--<gs:InputLanguageID Action="add" ID="0409:00000409" Default="true"/>-->

    </gs:InputPreferences>

    <!--location - Change location on Location tab to US-->

    <gs:LocationPreferences>

    <gs:GeoID Value="244"/>

    </gs:LocationPreferences>

    <!--User Locale - This changes formats to English(United States) ie M/dd/yyyy-->

    <gs:UserLocale>

    <gs:Locale Name="en-US" SetAsCurrent="true"/>

    </gs:UserLocale>


    </gs:GlobalizationServices>



This script will add in the US keyboard and set it as the system default keyboard

   <!--User List-->

   <gs:UserList>

   <gs:User UserID="Current"/>

   </gs:UserList>

   <!--input preferences - Keyboard languages-->

   <gs:InputPreferences>

   <!--Add keyboard US(English)-->
   <gs:InputLanguageID Action="add" ID="0409:00000409" Default="true"/>

   </gs:InputPreferences>

   </gs:GlobalizationServices>



That about sums it up.
Here are some additional helpful links:
http://msdn.microsoft.com/en-us/library/ms912389%28WinEmbedded.11%29.aspx
http://texhex.blogspot.com/2009/10/installing-and-configuring-language.html
http://msdn.microsoft.com/en-us/goglobal/bb896001
http://technet.microsoft.com/en-us/library/cc766503(WS.10).aspx

Solution 2:

Also make sure to set a new default keyboard before removing the keyboard that was the old default keyboard