Get OS Version / Friendly Name in C#(在 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# 中获取操作系统版本/友好名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 C# 中获取操作系统版本/友好名称


基础教程推荐
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01