Click here to Skip to main content
15,885,145 members
Home / Discussions / Windows Development
   

Windows Development

 
GeneralRe: Binding Pin
Samir Ibrahim6-Mar-22 21:09
Samir Ibrahim6-Mar-22 21:09 
GeneralRe: Binding Pin
RedDk5-Mar-22 10:21
RedDk5-Mar-22 10:21 
QuestionBatch file - If statement findstr Pin
User 1536543221-Oct-21 9:11
User 1536543221-Oct-21 9:11 
AnswerRe: Batch file - If statement findstr Pin
Dave Kreskowiak21-Oct-21 12:09
mveDave Kreskowiak21-Oct-21 12:09 
QuestionGetting the interactive user's display language from a service Pin
Daniel Pfeffer25-Aug-21 4:24
professionalDaniel Pfeffer25-Aug-21 4:24 
AnswerRe: Getting the interactive user's display language from a service Pin
Randor 25-Aug-21 10:08
professional Randor 25-Aug-21 10:08 
GeneralRe: Getting the interactive user's display language from a service Pin
Daniel Pfeffer25-Aug-21 10:56
professionalDaniel Pfeffer25-Aug-21 10:56 
GeneralRe: Getting the interactive user's display language from a service Pin
Randor 26-Aug-21 8:02
professional Randor 26-Aug-21 8:02 
Hi Daniel,

See if something like this would work for you:

C++
BOOL RegGetPreferredUILanguages(const PSID p, std::vector<std::wstring>& out_vector)
{
    LPWSTR szSid = nullptr;
    BOOL bRet = FALSE;
    if (ConvertSidToStringSidW(p, &szSid))
    {
        HKEY k;
        constexpr DWORD size = 256;
        WCHAR buffer[size];
        wsprintf(buffer, L"%s\\Control Panel\\Desktop", szSid);

        LSTATUS status = RegOpenKeyW(HKEY_USERS, buffer, &k);
        if (ERROR_SUCCESS == status)
        {
            DWORD dwNeeded = 0;
            std::vector<WCHAR> multi_sz;

            RegGetValue(k, nullptr, L"PreferredUILanguages", RRF_RT_REG_MULTI_SZ, nullptr, nullptr, &dwNeeded);
            multi_sz.resize(dwNeeded / sizeof(WCHAR));

            if (ERROR_SUCCESS == RegGetValue(k, nullptr, L"PreferredUILanguages", RRF_RT_REG_MULTI_SZ | RRF_ZEROONFAILURE, nullptr, &multi_sz[0], &dwNeeded))
            {
                std::wistringstream ss(std::wstring(multi_sz.begin(), multi_sz.end()));

                std::wstring lang;
                while (std::getline(ss, lang, L'\0'))
                {
                    if(lang.length())
                        out_vector.push_back(lang);
                }

                bRet = TRUE;
            }

            RegCloseKey(k);
        }

        LocalFree(szSid);
    }

    return bRet;
}


You would use it something like this:

C++
std::vector<std::wstring> langs;
RegGetPreferredUILanguages(pData->Sid, langs);
UINT index = 1;
for (auto lang : langs)
{
    wprintf(L"User Preferred UI Language at index %u is: %s \n", index++, lang.c_str());
}


My understanding is that the first entry is the current preferred UI language.

I have some additional comments:

1.) If you are doing this in a corporate environment then you might want to check for the domain/machine policy[^] first. The security policy is located in the registry at HKLM\Software\Policies\Microsoft\MUI\Settings and you would need to honor that.
2.) You will need to use a multi-tiered fallback. The HKCU\Control Panel\Desktop\PreferredUILanguages key will not exist if the user has not setup MUI and a default language. I believe you need fallback in this order:

* HKCU\Control Panel\Desktop\PreferredUILanguages (User prference) **might not be present**
* HKCU\Control Panel\Control Panel\International\Locale (User default) **always present**
* HKLM\SYSTEM\CurrentControlSet\Control\MUI\Settings\PreferredUILanguages (MUI default) **might not be present**
* HKLM\SYSTEM\CurrentControlSet\Control\Nls\Language\Default **always present**
* HKLM\SYSTEM\CurrentControlSet\Control\Nls\Language\InstallLanguage **always present**

The MUI keys are only present if the user has enabled MUI and installed multiple language packs. You can convert from LCID to locale with the LCIDToLocaleName function[^]. And use the LocaleNameToLCID function[^] for the reverse.

Here is how you would use them: (with the provided sample code)

C++
constexpr DWORD s = 256;
WCHAR buffer[s] = {0};
WCHAR name[LOCALE_NAME_MAX_LENGTH] = {0};
if (RegGetInternationaliations(pData->Sid, L"Locale", buffer, s))
{
    wprintf(L"Default User Hex locale: %s\n", buffer);
    DWORD id = wcstol(buffer, NULL, 16);
    wprintf(L"Default User Dec locale: %u\n", id);

    LCIDToLocaleName(id, name, LOCALE_NAME_MAX_LENGTH, LOCALE_ALLOW_NEUTRAL_NAMES);
    wprintf(L"Default User Locale Name: %s\n", name);
}


Let me know if this works out for you.

Best Wishes,
-David Delaune
GeneralRe: Getting the interactive user's display language from a service Pin
Daniel Pfeffer26-Aug-21 17:03
professionalDaniel Pfeffer26-Aug-21 17:03 
GeneralRe: Getting the interactive user's display language from a service Pin
Daniel Pfeffer31-Aug-21 10:03
professionalDaniel Pfeffer31-Aug-21 10:03 
GeneralRe: Getting the interactive user's display language from a service Pin
Randor 27-Sep-21 7:36
professional Randor 27-Sep-21 7:36 
GeneralRe: Getting the interactive user's display language from a service Pin
Daniel Pfeffer28-Sep-21 9:16
professionalDaniel Pfeffer28-Sep-21 9:16 
QuestionDisplaying a system modal message box in the system format Pin
Daniel Pfeffer4-Aug-21 1:49
professionalDaniel Pfeffer4-Aug-21 1:49 
AnswerRe: Displaying a system modal message box in the system format Pin
Richard MacCutchan4-Aug-21 3:12
mveRichard MacCutchan4-Aug-21 3:12 
GeneralRe: Displaying a system modal message box in the system format Pin
Daniel Pfeffer4-Aug-21 3:30
professionalDaniel Pfeffer4-Aug-21 3:30 
QuestionCheck if .exe-file, WITH A PATH(!!!), is running, from within a bat-file? Pin
arnold_w10-May-21 7:17
arnold_w10-May-21 7:17 
AnswerRe: Check if .exe-file, WITH A PATH(!!!), is running, from within a bat-file? Pin
Victor Nijegorodov10-May-21 9:31
Victor Nijegorodov10-May-21 9:31 
GeneralRe: Check if .exe-file, WITH A PATH(!!!), is running, from within a bat-file? Pin
arnold_w10-May-21 9:56
arnold_w10-May-21 9:56 
AnswerRe: Check if .exe-file, WITH A PATH(!!!), is running, from within a bat-file? Pin
arnold_w11-May-21 22:35
arnold_w11-May-21 22:35 
GeneralRe: Check if .exe-file, WITH A PATH(!!!), is running, from within a bat-file? Pin
Victor Nijegorodov11-May-21 22:47
Victor Nijegorodov11-May-21 22:47 
GeneralRe: Check if .exe-file, WITH A PATH(!!!), is running, from within a bat-file? Pin
arnold_w11-May-21 23:18
arnold_w11-May-21 23:18 
GeneralRe: Check if .exe-file, WITH A PATH(!!!), is running, from within a bat-file? Pin
Victor Nijegorodov11-May-21 23:49
Victor Nijegorodov11-May-21 23:49 
GeneralRe: Check if .exe-file, WITH A PATH(!!!), is running, from within a bat-file? Pin
arnold_w12-May-21 0:38
arnold_w12-May-21 0:38 
GeneralRe: Check if .exe-file, WITH A PATH(!!!), is running, from within a bat-file? Pin
Eddy Vluggen21-May-21 11:22
professionalEddy Vluggen21-May-21 11:22 
QuestionNeed Suggestions For Uninstalling Avast Secure Browser Pin
Gregorio Pollich19-Feb-21 2:51
Gregorio Pollich19-Feb-21 2:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.