Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Does anyone know how to change the keyboard layout for windows services and applications started by windows services. I have a server where every language / region / location option I can find is set to English UK / British but the keyboard layout name returned by services running on the server shows 409 which is English US. The knock on effect is that @ are interpreted as ~.
Posted
Comments
Bernhard Hiller 27-Mar-14 9:04am    
? I cannot follow. Do you talk about a Remote Desktop (RDP) Session to a Windows Terminal Server?
Steve Thresher 27-Mar-14 9:51am    
I'm talking about a windows service (services.msc). I've written a test service that just runs the following code when started:

protected override void OnStart(string[] args)
{
IntPtr hkl = GetKeyboardLayout(0);

string output = String.Format("GetKeyboardLayout: 0x{0:x} \n",unchecked((short)((uint)hkl >> 16)));

System.Diagnostics.Debug.WriteLine(output);

StringBuilder layoutName = new System.Text.StringBuilder(new string(' ', 256)); ;
GetKeyboardLayoutName(layoutName);

output = String.Format("GetKeyboardLayoutName: {0} \n", layoutName);

System.Diagnostics.Debug.WriteLine(output);
}

The output on the problem server looks like this:

GetKeyboardLayout: 0x409
GetKeyboardLayoutName: 00000409

They should both show 809 on a server configured for English UK.
Sergey Alexandrovich Kryukov 27-Mar-14 12:36pm    
Normally, Windows Services are quite agnostic about keyboard layouts. They don't have keyboard input. Not clear what do you want to achieve and why.
—SA

We have an automation layer built into our applications which records windows messages to be replayed later. This allows a user to 'record' the generation of a report and then 'play' that back when required. Part of the application in question is the recording of a recipient email address. When the playback is launched from a regular desktop the @ symbol appears correctly but when the playback is launched from a windows service the @ symbol (virtual key VK_OEM_3) in the recipient email address is interpreted as a ~ character which causes the SMTP email to fail. Creating a test service to dump the keyboard layout details to the debug window was just the simplest way to reproduce the problem with the least amount of steps possible. On my machine and other servers I've tested the keyboard layout is returned as 809, English UK, as expected.
 
Share this answer
 
In that case, you should also record the keyboard layout used by the application to be monitored, and the playback application should set its keyboard layout to the value stored in the recording.
 
Share this answer
 
De=stabilising software that's been running for years on multiple versions of Windows to handle one problem server is not the answer!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900