【问题标题】:How can I find the Windows Edition name [duplicate]如何找到 Windows 版本名称 [重复]
【发布时间】:2013-10-04 05:34:55
【问题描述】:

如何为我的 c# 应用程序找到 Microsoft Windows (操作系统名称)

例如“Windows 8 Pro”我是指操作系统中的版本。

【问题讨论】:

  • 我不认为 OSVersion 区分家庭、专业、终极
  • @Tilak 然后不要在解决方案中使用 OSVersion 并使用 WMI,就像副本中的链接说的那样。
  • 另见this link。一点点google searching 可以走很长的路
  • gunr2171 这也许是一种方式

标签: c# windows operating-system


【解决方案1】:

您可以从注册表中获取操作系统名称,但您需要查询 WMI 以获取体系结构和服务包信息:

using System.Diagnostics;
...
private string GetOperatingSystemInfo()
{
    RegistryKey operatingSystemKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
    string operatingSystemName = operatingSystemKey.GetValue("ProductName").ToString();

    ConnectionOptions options = new ConnectionOptions();
    // query any machine on the network     
    ManagementScope scope = new ManagementScope("\\\\machineName\\root\\cimv2", options);
    scope.Connect();
    // define a select query
    SelectQuery query = new SelectQuery("SELECT OSArchitecture, CSDVersion FROM Win32_OperatingSystem");
    ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);

    string osArchitecture = "";
    string osServicePack = "";

    foreach (ManagementObject mo in searcher.Get())
    {
        osArchitecture = mo["OSArchitecture"].ToString();
        osServicePack = mo["CSDVersion"].ToString();               
    }            
    return operatingSystemName + " " + osArchitecture + " " + osServicePack;                         
}

如果您想从 WMI 获得更多信息,请务必查看 MSDN 上的 Win32_OperatingSystem 类。

【讨论】:

  • 谢谢你的回答,我现在想测试一下
猜你喜欢
  • 2019-02-06
  • 1970-01-01
  • 2011-04-19
  • 2017-09-28
  • 2021-11-26
  • 2017-04-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多