How can I find the current Windows language from cmd?

前端 未结 8 1044
囚心锁ツ
囚心锁ツ 2021-02-04 12:02

I would like to run a script for each language. I need a way to find which os language is being used, using batch files. Both on windows XP, and on Windows 7.

8条回答
  •  情歌与酒
    2021-02-04 12:29

    You can't use InstallLanguage under HKLM\SYSTEM\CurrentControlSet\Control\nls\language
    because that's just what it says it is: Install Language
    Although you can directly install localized version of Windows, this is not always done, as it wasn't on my PC. Instead a language pack is applied, which is fine, but then Display Language is not the same as Install Language.
    Also if a user change his display language, InstallLanguage will not reflect the change. And there could be more users with different display languages.

    • Current User Display Language

    HKCU\Control Panel\Desktop
    PreferredUILanguages

    FOR /F "tokens=3" %%a IN ('reg query "HKCU\Control Panel\Desktop" /v PreferredUILanguages ^| find "PreferredUILanguages"') DO set UILanguage=%%a
    echo User Display Language: %UILanguage%
    


    There is difference between Local Machine language, System language and User language. There is also separate settings for BCD language, used for recovery and boot manager

    • Local Machine

    Install language is set upon installation and is never changed
    also a Default value for "HKLM\SYSTEM\CurrentControlSet\Control\nls\language" key is set to the same value. This value is wrongly read by some InstallShield setup programs, resulting in English interface on localized Windows.
    If you change Display language, new value is stored in

    HKLM\SYSTEM\CurrentControlSet\Control\MUI\Settings
    PreferredUiLanguages

    this will override InstallLanguage value under HKLM\SYSTEM\CurrentControlSet\Control\nls\language
    There is a mix-up in value types, while InstallLanguage is LCID, PreferredUiLanguages is LCID string. This language is then reported as Local Machine Language. It isn't User Display Language

    • System Language

    This is the language for System user.
    Before a user is logged on, this language is used.
    That means it is a language for Welcome screen, and for the OOBE.

    HKEY_USERS\S-1-5-18\Control Panel\Desktop\MuiCached
    MachinePreferredUILanguages



    There is also a WMI way to get OS language, but I didn't test which of these languages you'll get

    wmic os get locale, oslanguage, codeset

    FOR /F "tokens=2 delims==" %%a IN ('wmic os get OSLanguage /Value') DO set OSLanguage=%%a
    echo OS Language: %OSLanguage%
    

提交回复
热议问题