如何检测 Windows 的语言版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/202009/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to detect the language version of Windows
提问by gyrolf
Required is the true language version of the OS, not the user interface language or the current locale settings.
必需的是操作系统的真实语言版本,而不是用户界面语言或当前区域设置。
Use case: software installation which has to apply security settings and user account creation. The scripts have to know certain system properties like user group names in the original language of the OS.
用例:必须应用安全设置和用户帐户创建的软件安装。脚本必须知道某些系统属性,例如操作系统原始语言中的用户组名称。
(Should work with Windows XP, Windows Server 2003, Vista, ...)
(应该适用于 Windows XP、Windows Server 2003、Vista 等)
回答by R?mulo Ceccon
To detect the operating system language use GetSystemDefaultUILanguage.
要检测操作系统语言,请使用GetSystemDefaultUILanguage。
However, there are more straightforward ways to find things such as a known group name in Windows. For example, to get the name for the Usersgroup call CreateWellKnownSidwith WellKnownSidType = 27 (WinBuiltinUsersSid)
and then LookupAccountSid. The name for other well-known users and groupsmay be queried as well.
但是,有更直接的方法可以在 Windows 中查找诸如已知组名之类的内容。例如,要获取用户组的名称,先调用CreateWellKnownSid,WellKnownSidType = 27 (WinBuiltinUsersSid)
然后调用LookupAccountSid。也可以查询其他知名用户和组的名称。
回答by Chris Becke
All localized names in the OS have a language neutral way to access them for use by native applications and setup scripts. the administrators, users, guests groups and administrator account have well known SIDs that can be used in place of a localized name. An extra point to consider is that all the default names of the built in principals can be changed, and often are by well meaning but confused sys admins that belive that changing the domain admins account or group names to a non default equals increased security. You cannot rely on these things even being the correct name for the OS's installation language. Even worse, some of the language localizations change between OS releases for a language. So you would need to construct a very careful mapping between OS versions and expected names for languages.
操作系统中的所有本地化名称都有一种语言中立的方式来访问它们以供本机应用程序和安装脚本使用。管理员、用户、来宾组和管理员帐户具有众所周知的 SID,可用于代替本地化名称。需要考虑的额外一点是,内置主体的所有默认名称都可以更改,并且通常是善意但混淆的系统管理员,他们认为将域管理员帐户或组名称更改为非默认名称等于提高安全性。即使是操作系统安装语言的正确名称,您也不能依赖这些东西。更糟糕的是,某些语言本地化在操作系统版本之间会发生变化。因此,您需要在操作系统版本和语言的预期名称之间构建一个非常仔细的映射。
Rather don't. Find out how to build the locale neutral id for your scripting environment.
不如不要。了解如何为您的脚本环境构建区域设置中性 ID。
回答by gyrolf
My best solution so far: enumerate the local user accounts and groups and compare with a list of known names in different languages.
迄今为止我最好的解决方案:枚举本地用户帐户和组,并与不同语言的已知名称列表进行比较。