在 C# 中获取操作系统版本/友好名称
我目前正在开发一个 C# 项目。我想收集用户统计数据以更好地开发软件。我正在使用 C# 的 Environment.OS
功能,但它仅将操作系统名称显示为 Microsoft Windows NT
我希望能够检索 是操作系统的实际已知名称,例如 Windows XP、Windows Vista 或 Windows 7 等。
这可能吗?
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
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.
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
为
System.Management
添加引用和 using 语句,然后:Add a reference and using statements for
System.Management
, then:您确实应该尽量避免在本地使用 WMI。它非常方便,但在性能方面您付出了高昂的代价。想想懒惰税吧!
Kashish 关于注册表的回答并不适用于所有系统。下面的代码应该并且还包括服务包:
You should really try to avoid WMI for local use. It is very convenient but you pay dearly for it in terms of performance. Think laziness tax!
Kashish's answer about the registry does not work on all systems. Code below should and also includes the service pack:
添加对 Microsoft.VisualBasic 的 .NET 引用。然后调用:
来自 MSDN:
Add a .NET reference to Microsoft.VisualBasic. Then call:
From MSDN:
我希望你觉得这很有用
I hope that you find this useful
虽然这不是检测操作系统名称的完全 C# 方式,但下面的代码可以满足我的需求 -
注意:
Though this is not a fully C# way of detecting the OS Name, below code works for my needs-
Note:
此代码将获得完整的操作系统名称,例如“Windows 8.1 Pro”
this code will get the full os name like this "Windows 8.1 Pro"