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

查看:24
本文介绍了在 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.

这可能吗?

推荐答案

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;
}

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

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