Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Change keyboard layout

Posted on 2004-09-21
21
Medium Priority
?
971 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…
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…
Suggested Courses

730 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