我使用C#。我尝试获取当前操作系统的版本:
OperatingSystem os = Environment.OSVersion;
Version ver = os.Version;
我使用的是Windows 10操作系统:6.2。
但6.2实际上是指Windows 8或WindowsServer 2012(.net中检测Windows版本)。
我找到了以下解决方案(如何检测我的应用程序是否在运行Windows 10)。
static bool IsWindows10()
{
var reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
string productName = (string)reg.GetValue("ProductName");
return productName.StartsWith("Windows 10");
}
这是在C#中获取当前版本的最佳方法吗?