Solved

Change keyboard layout

Posted on 2004-09-21
21
957 Views
Last Modified: 2012-05-05
Hi,
  I'm looking for a vbs script that can change the keyboard layout on a given computer ( running Windows 2000 / XP ). The problem we're experiencing is for some reason when some users log on, they get the US keymap instead of the UK keymap. This means that they can't get several crucial characters and end up complaining. So, does anyone have a vb script that I could get them to run on login that would automatically set the right keyboard? The users do have permission to change keyboard but not the know how.

Hope you guys can help!
0
Comment
Question by:petepalmer
  • 5
  • 5
  • 5
  • +3
21 Comments
 
LVL 16

Expert Comment

by:jimbobmcgee
ID: 12113735
Have you tried
    SetLocale 2057    '2057 being the UK code

or
    SetLocale en-gb
0
 
LVL 1

Author Comment

by:petepalmer
ID: 12113782
tried that - doesn't seem to do anything I'm afraid
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12114028
You can use WinAPI functio LoadKeyboardLayout:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput
/keyboardinputreference/keyboardinputfunctions/loadkeyboardlayout.asp

Also take a look to this article:
http://support.microsoft.com/default.aspx?scid=kb;en-us;139571
To implement in Visual basic, take a look to:
http://www.mentalis.org/apilist/LoadKeyboardLayout.shtml

Good luck,
Jaime.
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 13

Expert Comment

by:Michael_D
ID: 12114047
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12114111
Notice that changing Windows Registry directly, you will not have an inmediat effect. But still will be useful to "scan" registry to know installed keyboard layouts, as pointed out in MSDN article I've posted.
0
 
LVL 16

Expert Comment

by:jimbobmcgee
ID: 12114166
Out of interest, Jaime, how do you declare that function from within a VBS?

I tried

   Declare Function LoadKeyboardLayout Lib "user32.dll" Alias "LoadKeyboardLayoutA" (ByVal pwszKLID As String, ByVal flags As Long) As Long

as I would in VB6 and it failed with a syntax error...
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12114443
try to remove the alias (Alias "LoadKeyboardLayoutA")
0
 
LVL 14

Expert Comment

by:Matti
ID: 12114686
Hi!

This is module level code:

Public Userkeyboard As String
Public Declare Function LoadKeyboardLayout Lib "user32" Alias "LoadKeyboardLayoutA" (ByVal pwszKLID As String, ByVal Flags As Long) As Long
Public Declare Function GetKeyboardLayoutName Lib "user32" Alias "GetKeyboardLayoutNameA" (ByVal pwszKLID As String) As Long
Public Const KLF_ACTIVATE = &H1


Public Sub Askkeyboard()
On Error Resume Next
Dim X&, pwszKLI2 As String * 8
X = GetKeyboardLayoutName(pwszKLI2)
Userkeyboard = pwszKLI2
End Sub

Public Sub Restorekeyboard()
Call LoadKeyboardLayout(Userkeyboard, KLF_ACTIVATE)
End Sub

Public Function ChKeyboard(langnum As Long) As Long
On Error Resume Next
Dim X&, setKB As String
DoEvents
Select Case asettelu
Case 0
setKB = "00000419"
Case 1
setKB = "00010419"
Case 2
setKB = "00000423"
Case Else
setKB = "00000419"
End Select
DoEvents
Call LoadKeyboardLayout(setKB, KLF_ACTIVATE)
End Function

Test code on form:
Private Sub Form_Load()
Askkeyboard
Call ChKeyboard(2)
End Sub

Private Sub Form_Unload(Cancel As Integer)
Restorekeyboard
End Sub

More layouts and their constant values you will found from registry
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Nls\LocaleMapIDs
Install more keyboards from windows CD.


Matti

0
 
LVL 1

Author Comment

by:petepalmer
ID: 12114985
Well I'm looking for some code that I can run as is to set the keyboard to gb :)
0
 
LVL 16

Expert Comment

by:jimbobmcgee
ID: 12121344
Jaime/Matti

Declare Function LoadKeyboardLayout Lib "user32.dll" (ByVal pwszKLID As String, ByVal flags As Long)

returns a syntax error at char 9, when used in a VBS; which looks like it doesn't like the word 'Function'.

How do you call from the API, in a VBS?
0
 
LVL 14

Expert Comment

by:Matti
ID: 12122041
Hi, jimbobmcgee!

It's important that this pwszKLID string is fixed lenght 8 char long, won't work if it's not. I don't use VBS on this macine so can't test, but think there is a bug on this API function.

Matti
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12122715
I think there is no problem with pwszKLID, but, since you are declaring a function you must declare return type:
Declare Function LoadKeyboardLayout Lib "user32.dll" (ByVal pwszKLID As String, ByVal flags As Long) as Long
0
 
LVL 1

Author Comment

by:petepalmer
ID: 12123459
This is all very interesting but I'm not sure how it solves my problem :)

For the 500 points I either need a working VB script or a compiled VB application - as I don't have Visual Studio to compile it myself.

Thanks in advance!
0
 
LVL 16

Expert Comment

by:jimbobmcgee
ID: 12128164
> I think there is no problem with pwszKLID, but, since you are declaring a function you must declare return type:
> Declare Function LoadKeyboardLayout Lib "user32.dll" (ByVal pwszKLID As String, ByVal flags As Long) as Long

Still it returns a syntax error at char 9 (starting at function)

> This is all very interesting but I'm not sure how it solves my problem :)

If you cannot 'declare' the LoadKeyboardLayout API, you can't use the above code in VBS.  If you want an EXE, send an email to whoever you prefer; I'm sure the listed code will work...

:)
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12128349
Take a look to this article about using WinAPI functions in VBScript. Hope to be useful.
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_10115990.html
0
 
LVL 1

Author Comment

by:petepalmer
ID: 12563839
I was unable to use any of the options to do what I wanted therefore I'm going to request a refund.
0
 
LVL 1

Author Comment

by:petepalmer
ID: 12563887
Looking back through the posts, whilst the information might be perfectly acceptable, I was unable to use it to create a script or program that would allow users to set their own keyboard. If someone can provide the information in a script or program form that works, I'll happily accept it - but as it stands I'm not able to use the information I'm afraid.
0
 
LVL 16

Expert Comment

by:jimbobmcgee
ID: 12697501
As mentioned, if you want an executable, send someone here an email (like me) and we'll compile for you, using one of the solutions you choose above...

J.
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12848596
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question