【问题标题】:(C#) Detect type of Windows OS (non-localized) [duplicate](C#)检测 Windows 操作系统的类型(非本地化)[重复]
【发布时间】:2013-03-19 15:54:18
【问题描述】:

我需要检测安装的是什么类型(版本)的 Windows 操作系统。我的意思是,例如:“家庭”、“企业”或“专业”。请不要问为什么(我已经与需求向导进行了艰苦的斗争)。

现在的问题是 Windows 类型似乎是本地化的,我需要一种方法在 switch 语句中使用它们来执行不同的行为。

现在我这样做:

_os = (from x in new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem").Get().OfType<ManagementObject>()
       select x.GetPropertyValue("Caption")).First().ToString().Trim();
switch (_os)
{   
    case "Microsoft Windows XP Professional":
        {
            // Do professional stuff...
            break;
        }
    case "Microsoft Windows 7 Professional":
    case "Microsoft Windows 7 Ultimate":
    case "Microsoft Windows 7 Enterprise":
        {
            // Do ultimate enterprisey professional stuff
            break;
        }
    default:
        {
            // File not found
            break;
        }
}

有谁知道如何避免遇到本地化问题?

【问题讨论】:

  • 你看这里了吗? codeproject.com/Articles/73000/…
  • 我会说这不是完全重复的(虽然我错过了那个问题),因为那里的答案包括获取价值——但它可能是本地化的,我想避免这是我这个问题的重点。

标签: c# windows


【解决方案1】:

关于 Codeproject 是一篇不错的文章(带有 dll)来做到这一点:

Getting Operating System Version Info - Even for Windows 8!

他的奶酪来自:

Determine Windows Version and Edition with C#

【讨论】:

    【解决方案2】:

    参见Win32_OperatingSystem 类中的OperatingSystemSKU 属性,这是基于uint 的枚举。

    【讨论】:

    • 这很好,但不适用于 Windows XP。
    • @AmadeusHein:对于 XP,请参阅 OSProductSuite 属性。
    【解决方案3】:

    您可以 P/Invoke GetProductInfo 原生 API。 C#中的用法和示例can be found here

    虽然它仅在 Vista 及更高版本中受支持。

    这里是an example,它是如何在 C++ 中完成的,可以很容易地 P/Invoked

    对于 XP,恐怕没有任何方法可以以非本地化方式获取此信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-20
      • 1970-01-01
      • 2011-07-08
      • 1970-01-01
      • 2012-09-20
      • 1970-01-01
      • 1970-01-01
      • 2022-01-10
      相关资源
      最近更新 更多