如何找到Windows Edition名称 [英] How can I find the Windows Edition name

查看:215
本文介绍了如何找到Windows Edition名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I find the Microsoft Windows (Os name) for my c# application.

例如"Windows 8 Pro",我指的是来自操作系统的版本.

such as 'Windows 8 Pro' I mean the Edition from the os.

推荐答案

您可以从注册表中获取操作系统名称,但需要向WMI查询架构和Service Pack信息:

You can get the operating system name from the registry but you need to query WMI for the architecture and the service pack information:

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中获取更多信息,请确保查看

If you want more information from WMI, be sure to take a look at the Win32_OperatingSystem class on MSDN.

这篇关于如何找到Windows Edition名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆