Hello,

I am trying to create a batch file that changes the keyboard languages for every user on a computer. I managed to make the batch file work for the user who is logged in but it does nothing for the other users on the PC. This is what I have up to now:

ml_kb_layouts.bat (this is the file I run as an administrator):

@ECHO OFF

G:
CD kbreg
REM FR Layouts
REG LOAD "HKEY_USERS\..Français" "C:\Users\Default\NTUSER.DAT"
REG IMPORT rem_fr_kb_layout.reg
REG IMPORT fr_kb_layout.reg
REG UNLOAD "HKEY_USERS\..Français"
REM EN Layouts
REG LOAD "HKEY_USERS\.English" "C:\Users\Default\NTUSER.DAT"
REG IMPORT rem_en_kb_layout.reg
REG IMPORT en_kb_layout.reg
REG UNLOAD "HKEY_USERS\.English"
REM aFR Layouts
REG LOAD "HKEY_USERS\.AccessibleFR" "C:\Users\Default\NTUSER.DAT"
REG IMPORT rem_afr_kb_layout.reg
REG IMPORT afr_kb_layout.reg
REG UNLOAD "HKEY_USERS\.AccessibleFR"
REM aEN Layouts
REG LOAD "HKEY_USERS\AccessibleEN" "C:\Users\Default\NTUSER.DAT"
REG IMPORT rem_aen_kb_layout.reg
REG IMPORT aen_kb_layout.reg
REG UNLOAD "HKEY_USERS\AccessibleEN"
PAUSE

aen_kb_layout.reg :

Windows Registry Editor Version 5.00
[HKEY_USERS\S-1-5-21-841078154-175965516-1052724368-1012\Keyboard Layout]
[HKEY_USERS\S-1-5-21-841078154-175965516-1052724368-1012\Keyboard Layout\Preload]
"2"="00000c0c"
"1"="00001009"
[HKEY_USERS\S-1-5-21-841078154-175965516-1052724368-1012\Keyboard Layout\Substitutes]
"00000c0c"="00011009"
"00001009"="00000409"
[HKEY_USERS\S-1-5-21-841078154-175965516-1052724368-1012\Keyboard Layout\Toggle]

afr_kb_layout.reg :

Windows Registry Editor Version 5.00
[HKEY_USERS\S-1-5-21-841078154-175965516-1052724368-1010\Keyboard Layout]
[HKEY_USERS\S-1-5-21-841078154-175965516-1052724368-1010\Keyboard Layout\Preload]
"1"="00000c0c"
"2"="00001009"
[HKEY_USERS\S-1-5-21-841078154-175965516-1052724368-1010\Keyboard Layout\Substitutes]
"00000c0c"="00011009"
"00001009"="00000409"
[HKEY_USERS\S-1-5-21-841078154-175965516-1052724368-1010\Keyboard Layout\Toggle]

en_kb_layout.reg :

Windows Registry Editor Version 5.00
[HKEY_USERS\S-1-5-21-841078154-175965516-1052724368-1011\Keyboard Layout]
[HKEY_USERS\S-1-5-21-841078154-175965516-1052724368-1011\Keyboard Layout\Preload]
"2"="00000c0c"
"1"="00001009"
[HKEY_USERS\S-1-5-21-841078154-175965516-1052724368-1011\Keyboard Layout\Substitutes]
"00000c0c"="00011009"
"00001009"="00000409"
[HKEY_USERS\S-1-5-21-841078154-175965516-1052724368-1011\Keyboard Layout\Toggle]

fr_kb_layout.reg :

Windows Registry Editor Version 5.00
[HKEY_USERS\S-1-5-21-841078154-175965516-1052724368-1009\Keyboard Layout]
[HKEY_USERS\S-1-5-21-841078154-175965516-1052724368-1009\Keyboard Layout\Preload]
"1"="00000c0c"
"2"="00001009"
[HKEY_USERS\S-1-5-21-841078154-175965516-1052724368-1009\Keyboard Layout\Substitutes]
"00000c0c"="00011009"
"00001009"="00000409"
[HKEY_USERS\S-1-5-21-841078154-175965516-1052724368-1009\Keyboard Layout\Toggle]

rem_aen_kb_layout.reg :

Windows Registry Editor Version 5.00
[-HKEY_USERS\S-1-5-21-841078154-175965516-1052724368-1012\Keyboard Layout\Preload]
[-HKEY_USERS\S-1-5-21-841078154-175965516-1052724368-1012\Keyboard Layout\Substitutes]

rem_afr_kb_layout.reg :

Windows Registry Editor Version 5.00
[-HKEY_USERS\S-1-5-21-841078154-175965516-1052724368-1010\Keyboard Layout\Preload]
[-HKEY_USERS\S-1-5-21-841078154-175965516-1052724368-1010\Keyboard Layout\Substitutes]

rem_en_kb_layout.reg :

Windows Registry Editor Version 5.00
[-HKEY_USERS\S-1-5-21-841078154-175965516-1052724368-1011\Keyboard Layout\Preload]
[-HKEY_USERS\S-1-5-21-841078154-175965516-1052724368-1011\Keyboard Layout\Substitutes]

rem_fr_kb_layout.reg :

Windows Registry Editor Version 5.00
[-HKEY_USERS\S-1-5-21-841078154-175965516-1052724368-1009\Keyboard Layout\Preload]
[-HKEY_USERS\S-1-5-21-841078154-175965516-1052724368-1009\Keyboard Layout\Substitutes]

This is what I get in the command prompt:

C:\Windows\system32>´╗┐@ECHO OFF
'´╗┐@ECHO' is not recognized as an internal or external command,
operable program or batch file.
C:\Windows\system32>G:
G:\>CD kbreg
G:\kbreg>REM FR Layouts
G:\kbreg>REG LOAD "HKEY_USERS\..Français" "C:\Users\Default\NTUSER.DAT"
The operation completed successfully.
G:\kbreg>REG IMPORT rem_fr_kb_layout.reg
The operation completed successfully.
G:\kbreg>REG IMPORT fr_kb_layout.reg
ERROR: Error accessing the registry.
G:\kbreg>REG UNLOAD "HKEY_USERS\..Français"
The operation completed successfully.
G:\kbreg>REM EN Layouts
G:\kbreg>REG LOAD "HKEY_USERS\.English" "C:\Users\Default\NTUSER.DAT"
The operation completed successfully.
G:\kbreg>REG IMPORT rem_en_kb_layout.reg
The operation completed successfully.
G:\kbreg>REG IMPORT en_kb_layout.reg
ERROR: Error accessing the registry.
G:\kbreg>REG UNLOAD "HKEY_USERS\.English"
The operation completed successfully.
G:\kbreg>REM aFR Layouts
G:\kbreg>REG LOAD "HKEY_USERS\.AccessibleFR" "C:\Users\Default\NTUSER.DAT"
The operation completed successfully.
G:\kbreg>REG IMPORT rem_afr_kb_layout.reg
The operation completed successfully.
G:\kbreg>REG IMPORT afr_kb_layout.reg
ERROR: Error accessing the registry.
G:\kbreg>REG UNLOAD "HKEY_USERS\.AccessibleFR"
The operation completed successfully.
G:\kbreg>REM aEN Layouts
G:\kbreg>REG LOAD "HKEY_USERS\AccessibleEN" "C:\Users\Default\NTUSER.DAT"
The operation completed successfully.
G:\kbreg>REG IMPORT rem_aen_kb_layout.reg
The operation completed successfully.
G:\kbreg>REG IMPORT aen_kb_layout.reg
ERROR: Error accessing the registry.
G:\kbreg>REG UNLOAD "HKEY_USERS\AccessibleEN"
The operation completed successfully.
G:\kbreg>PAUSE
Press any key to continue . . .

As you can see, I get errors for the all the users except for the one that's currently signed in (in the example above I was signed in in the "English" user account). Even for the commands that aren't showing any errors, the script simply isn't making any changes to the other users.

0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Answers

0
This would be better handled with group policy. Here's a page with some information:
http://social.technet.microsoft.com/wiki/contents/articles/6281.how-to-set-the-keyboard-layout-through-group-policy-gpo.aspx

If you really want to use a script then you would need to first load each user's registry hive, then import the keys to their loaded hive, then unload. You can use the reg.exe command to load and unload the hive.
Answered 09/04/2014 by: chucksteel
Red Belt

Please log in to comment
0
What I would recommend is that you insert pause statements in your batch file and then check each line of code has executed and done what you expect.  Your REG LOAD commands - I don't see any step which would create, for example, the registry path HKEY_USERS\AccessibleEN before you run the REG LOAD operation. Since \AccessibleEN does not exist under HKEY_USERS, and REG LOAD does not create missing paths in the registry, this may be where your code is breaking down.  Frankly, you only need one "working folder" in the registry and you can load and unload from the same folder to keep the code simple.

However, the group policy solution is so much easier that I would suggest you consider this seriously.   
Answered 09/04/2014 by: EdT
Red Belt

Please log in to comment
Answer this question or Comment on this question for clarity
Admin Script Editor
Admin Script Editor is an integrated scripting environment available free here at ITNinja

Share