Solved

Change keyboard layout

Posted on 2004-09-21
21
945 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
Comment Utility
Have you tried
    SetLocale 2057    '2057 being the UK code

or
    SetLocale en-gb
0
 
LVL 1

Author Comment

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

Expert Comment

by:Jaime Olivares
Comment Utility
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
 
LVL 13

Expert Comment

by:Michael_D
Comment Utility
0
 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
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
Comment Utility
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
Comment Utility
try to remove the alias (Alias "LoadKeyboardLayoutA")
0
 
LVL 14

Expert Comment

by:Matti
Comment Utility
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
Comment Utility
Well I'm looking for some code that I can run as is to set the keyboard to gb :)
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 16

Expert Comment

by:jimbobmcgee
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
> 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now