Detecting the active display language in windows 7 upwards
Detecting the active display language in windows 7 upwards
Hi,
i am trying to correctly and reliably detect the currently used display language of a windows installation. It is simple to do by scanning the output, but i have'nt found a working reliable API way so far.
For exaple my main machine is using an english windows7 ultimate installation which has the german language pack installed as optional display language pack. If i call system commands on the commandline like "diskpart", the output differs depending on the display language i select.
The topic has been brought up on other forums including slashdot and there seems to be an easy solution by api calls like GetSystemDefaultLangID_() or GetUserDefaultLangID_() but none of them works reliably in windows 7 and windows 10 for me.
Does anybody know a reliable win32 API way to do it?
MSI maybe? It should have the answer, but where?
Thanks in advance!
i am trying to correctly and reliably detect the currently used display language of a windows installation. It is simple to do by scanning the output, but i have'nt found a working reliable API way so far.
For exaple my main machine is using an english windows7 ultimate installation which has the german language pack installed as optional display language pack. If i call system commands on the commandline like "diskpart", the output differs depending on the display language i select.
The topic has been brought up on other forums including slashdot and there seems to be an easy solution by api calls like GetSystemDefaultLangID_() or GetUserDefaultLangID_() but none of them works reliably in windows 7 and windows 10 for me.
Does anybody know a reliable win32 API way to do it?
MSI maybe? It should have the answer, but where?
Thanks in advance!
Re: Detecting the active display language in windows 7 upwar
Tested with Windows 10
Code: Select all
kbd$ = Space(12)
OpenWindow(0,0,0,100,100,"test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
StringGadget(0,0,0,0,0,"") ;Dummy Gadget
ButtonGadget(1,10,60,120,20,"Get Active Language")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 0
Select EventType()
Case #PB_EventType_Focus
GetKeyboardLayoutName_(@kbd$)
Debug kbd$
EndSelect
Case 1
SetFocus_(GadgetID(0))
EndSelect
EndSelect
Until Quit = 1
End
Code: Select all
kbd$ = Space(12)
OpenWindow(0,0,0,120,24,"test", #PB_Window_BorderLess | #PB_Window_ScreenCentered)
StringGadget(0,0,0,0,0,"") ;Dummy Gadget
ButtonGadget(1,0,0,120,24,"Get Active Language")
Repeat
Select WaitWindowEvent()
Case #WM_CHAR
Quit = EventwParam()
Case #PB_Event_Gadget
Select EventGadget()
Case 0
Select EventType()
Case #PB_EventType_Focus
GetKeyboardLayoutName_(@kbd$)
SetActiveGadget(-1)
MessageRequester("Info","Active Keboard : "+kbd$,#MB_OK|#MB_ICONINFORMATION)
EndSelect
Case 1
SetFocus_(GadgetID(0))
EndSelect
EndSelect
Until Quit = 27
End
Egypt my love
- VB6_to_PBx
- Enthusiast
- Posts: 625
- Joined: Mon May 09, 2011 9:36 am
Re: Detecting the active display language in windows 7 upwar
Rashad , thank you for your Codes above , as i needed that also !
much more additional info in these 2 Links :
https://docs.microsoft.com/en-us/window ... uage-packs
https://docs.microsoft.com/en-us/window ... or-windows
much more additional info in these 2 Links :
https://docs.microsoft.com/en-us/window ... uage-packs
https://docs.microsoft.com/en-us/window ... or-windows
PureBasic .... making tiny electrons do what you want !
"With every mistake we must surely be learning" - George Harrison
Re: Detecting the active display language in windows 7 upwar
Thanks Rashad, but thats always 0407 (keyboard language name - just like MSI win32_operatingsystem\locale). What i need is the display language setting instead.
Re: Detecting the active display language in windows 7 upwar
Check the Registry for
Windows 10 :
HKCU\Control Panel\Desktop\MuiCached
For other Windows versions
HKCU\Control Panel\Desktop\MultiUILanguageId
Windows 10 :
HKCU\Control Panel\Desktop\MuiCached
For other Windows versions
HKCU\Control Panel\Desktop\MultiUILanguageId
Code: Select all
sRemMachName.s = ""
lTopLevelKey.l = #HKEY_CURRENT_USER
sKeyName.s = "Control Panel\Desktop\MuiCached"
sValueName.s = "MachinePreferredUILanguages"
Procedure.l QueryValueEx(lhkey.l, szValueName.s)
Shared vValue.s
cch = 255
sValue.s = Space(255)
lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, 0, @cch)
Select lType
Case #REG_MULTI_SZ
lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, @sValue.s, @cch)
If lrc = 0
vValue.s = Left(sValue.s, cch-1)
Else
vValue.s = "Empty"
EndIf
Default
lrc = -1
EndSelect
ProcedureReturn lrc
EndProcedure
lRetVal = RegConnectRegistry_(sRemMachName, lTopLevelKey.l, @lHKeyhandle)
lRetVal = RegOpenKeyEx_(lHKeyhandle, sKeyName, 0, #KEY_ALL_ACCESS, @lhkey)
lRetVal = QueryValueEx(lhkey, sValueName)
RegCloseKey_(lhkey)
If lRetVal = 0
Debug vValue.s
EndIf
Egypt my love
Re: Detecting the active display language in windows 7 upwar
Thanks but same problem - it reports en-us while the german language is active (de-de i guess) in win7.
Maybe its just a win7 problem?
\
ps: a registry search and 3 tests did seem to point at hkey_currentuser\control panel\Desktop\MuiCached\MachinePreferedUILanguages in win7
Maybe its just a win7 problem?
\
ps: a registry search and 3 tests did seem to point at hkey_currentuser\control panel\Desktop\MuiCached\MachinePreferedUILanguages in win7
Last edited by Bitblazer on Mon Apr 15, 2019 9:11 pm, edited 1 time in total.
Re: Detecting the active display language in windows 7 upwar
When you start your OS
What is the Active display language ?
What is the Active display language ?
Egypt my love
Re: Detecting the active display language in windows 7 upwar
This works with win7 even if you switch the language after boot. Thanks Rashad.
Code: Select all
sRemMachName.s = ""
lTopLevelKey.l = #HKEY_CURRENT_USER
sKeyName.s = "Control Panel\Desktop\"
sValueName.s = "PreferredUILanguages"
Procedure.l QueryValueEx(lhkey.l, szValueName.s)
Shared vValue.s
cch = 255
sValue.s = Space(255)
lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, 0, @cch)
Select lType
Case #REG_MULTI_SZ
lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, @sValue.s, @cch)
If lrc = 0
vValue.s = Left(sValue.s, cch-1)
Else
vValue.s = "Empty"
EndIf
Default
lrc = -1
EndSelect
ProcedureReturn lrc
EndProcedure
lRetVal = RegConnectRegistry_(sRemMachName, lTopLevelKey.l, @lHKeyhandle)
lRetVal = RegOpenKeyEx_(lHKeyhandle, sKeyName, 0, #KEY_ALL_ACCESS, @lhkey)
lRetVal = QueryValueEx(lhkey, sValueName)
RegCloseKey_(lhkey)
If lRetVal = 0
Debug vValue.s
EndIf
Re: Detecting the active display language in windows 7 upwar
There is no such key in my system (win 7x64)
This code works:lTopLevelKey.l = #HKEY_CURRENT_USER
sKeyName.s = "Control Panel\Desktop\"
sValueName.s = "PreferredUILanguages"
Code: Select all
sRemMachName.s = ""
lTopLevelKey.l = #HKEY_CURRENT_USER
sKeyName.s = "Control Panel\International"
sValueName.s ="LocaleName" ; or "sLanguage" ; or "sCountry"
Procedure.l QueryValueEx(lhkey.l, szValueName.s)
Shared vValue.s
cch = 255
sValue.s = Space(255)
lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, 0, @cch)
Select lType
Case #REG_SZ
lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, @sValue.s, @cch)
If lrc = 0
vValue.s = Left(sValue.s, cch-1)
Else
vValue.s = "Empty"
EndIf
Default
lrc = -1
EndSelect
ProcedureReturn lrc
EndProcedure
lRetVal = RegConnectRegistry_(sRemMachName, lTopLevelKey.l, @lHKeyhandle)
lRetVal = RegOpenKeyEx_(lHKeyhandle, sKeyName, 0, #KEY_ALL_ACCESS, @lhkey)
lRetVal = QueryValueEx(lhkey, sValueName)
RegCloseKey_(lhkey)
If lRetVal = 0
Debug vValue.s
EndIf
Re: Detecting the active display language in windows 7 upwar
beware - on my english win7 ultimate installation with two installed display languages (german and english), the following keys all point to germankvitaliy wrote:There is no such key in my system (win 7x64)This code works:lTopLevelKey.l = #HKEY_CURRENT_USER
sKeyName.s = "Control Panel\Desktop\"
sValueName.s = "PreferredUILanguages"Code: Select all
sRemMachName.s = "" lTopLevelKey.l = #HKEY_CURRENT_USER sKeyName.s = "Control Panel\International" sValueName.s ="LocaleName" ; or "sLanguage" ; or "sCountry" Procedure.l QueryValueEx(lhkey.l, szValueName.s) Shared vValue.s cch = 255 sValue.s = Space(255) lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, 0, @cch) Select lType Case #REG_SZ lrc = RegQueryValueEx_(lhkey, szValueName, 0, @lType, @sValue.s, @cch) If lrc = 0 vValue.s = Left(sValue.s, cch-1) Else vValue.s = "Empty" EndIf Default lrc = -1 EndSelect ProcedureReturn lrc EndProcedure lRetVal = RegConnectRegistry_(sRemMachName, lTopLevelKey.l, @lHKeyhandle) lRetVal = RegOpenKeyEx_(lHKeyhandle, sKeyName, 0, #KEY_ALL_ACCESS, @lhkey) lRetVal = QueryValueEx(lhkey, sValueName) RegCloseKey_(lhkey) If lRetVal = 0 Debug vValue.s EndIf
Code: Select all
lTopLevelKey.l = #HKEY_CURRENT_USER
sKeyName.s = "Control Panel\International"
sValueName.s ="LocaleName" ; or "sLanguage" ; or "sCountry"
Code: Select all
lTopLevelKey.l = #HKEY_CURRENT_USER
sKeyName.s = "Control Panel\Desktop\MuiCached"
sValueName.s ="MachinePreferredUIlanguages"
So i guess we should use that key and only if it doesnt exist, use the others as fallback option. Thats what im going to do now (and probably evaluate it by calling an OS tool and check which language the tool actually uses . What a mess