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# 中获取操作系统版本/友好名称
基础教程推荐
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- WPF 模态进度窗口 2022-01-01
