Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VBS script for changing keyboard locale

2,001 views
Skip to first unread message

Slinks

unread,
Dec 14, 2004, 6:08:23 PM12/14/04
to
Hi,

I am trying to set the standard language for the keyboard on a machine,
does anyone know how to do this using a vbs script?

thanks in advance

Simon

Torgeir Bakken (MVP)

unread,
Dec 15, 2004, 2:02:28 AM12/15/04
to
Slinks wrote:

> I am trying to set the standard language for the keyboard on
> a machine, does anyone know how to do this using a vbs script?

Hi

NT4\Win2k\WinXP:

You can do it with registry manipulation. You need to monitor what
happens under the registry keys

HKCU\Keyboard Layout\Preload\
and
HKCU\Keyboard Layout\Substitutes\

when you do it manually to get which data to manipulate. It is only a
few Input Locales that adds something under the Substitutes key.

Under the Preload key there will be one or more values with the name 1
(and eventually 2, 3 and so on.) It is 1 that always is the Default
Input Locale.

If you only have one Input Locale, and want to substitute it with
another, just overwrite the one under 1. If you want to add it to the
existing list (not substitute), you will need to find the next
available number and add it. If you in addition want to make the new
one default, you must swap it with 1.

NOTE: You need to log out and on again to see the change!

Here is a script that adds the Spanish (international) Input Locale to
the existing list (it does not change the default value):


'--------------------8<----------------------

sSpanishPreload = "00000c0a"
sSpanishSubstValue = "00000c0a"
sSpanishSubstData = "0000040a"

sPreloadBase = "HKCU\Keyboard Layout\Preload\"
sSubstBase = "HKCU\Keyboard Layout\Substitutes\"

Set oShell = CreateObject("WScript.Shell")

iPreloadIndex = 0

' unlikely that the user has more than 20 Input Locales
For i = 1 To 20
If Not RegValueExists(sPreloadBase & i)Then
' Next available number found!
iPreloadIndex = i
Exit For
Else
sTmp = oShell.RegRead(sPreloadBase & i)
If LCase(sTmp) = LCase(sSpanishPreload) Then
' Input Locale exists already. Aborting
Exit For
End If
End If
Next

If iPreloadIndex > 1 Then
' enable taskbar icon for user selection of input locale
oShell.RegWrite _
"HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\internat.exe", _
"internat.exe"
End If

If iPreloadIndex <> 0 Then
oShell.RegWrite sPreloadBase & iPreloadIndex, sSpanishPreload
oShell.RegWrite sSubstBase & sSpanishSubstValue, sSpanishSubstData
MsgBox "You must logoff to see the new Input Locale"
End If


Function RegValueExists(sRegValue)
' Returns True or False based of the existence of a registry value.
Dim oShell, RegReadReturn
Set oShell = CreateObject("WScript.Shell")
RegValueExists = True ' init value
On Error Resume Next
RegReadReturn = oShell.RegRead(sRegValue)
If Err.Number <> 0 Then
RegValueExists = False
End if
On Error Goto 0
End Function

'--------------------8<----------------------


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

Slinks

unread,
Dec 15, 2004, 1:30:37 PM12/15/04
to
Hi,

thanks for your help

regards
Simon

0 new messages