获取OS版本/友好名称在C# [英] Get OS Version / Friendly Name in C#

查看:275
本文介绍了获取OS版本/友好名称在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前工作的一个C#项目。我想收集用户统计数据,以便更好地开发软件。我使用C#的,但其只显示为类似操作系统的名称 Environment.OS 功能的Microsoft Windows NT ...

I am currently working on a C# project. I want to collect users statistics to better develop the software. I am using the Environment.OS feature of C# but its only showing the OS name as something like Microsoft Windows NT ...

我要的是能为检索操作系统的实际熟知的名字的像不管是的Windows XP,Windows Vista或Windows 7

What I want to be able to retrieve is the actual known name of the OS like whether it is Windows XP, Windows Vista or Windows 7 and etc.

这可能吗?

感谢你能提供任何帮助。

Thanks for any help you can offer.

推荐答案

添加一个引用,并用语句 System.Management ,则:

Add a reference and using statements for System.Management, then:

public static string GetOSFriendlyName()
{
    string result = string.Empty;
    ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Caption FROM Win32_OperatingSystem");
    foreach (ManagementObject os in searcher.Get())
    {
        result = os["Caption"].ToString();
        break;
    }
    return result;
}

这篇关于获取OS版本/友好名称在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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