我想检查运行的窗口是 windows 8 还是 windows 8.1。 使用 Windows 主要检查
6.2 -> 赢 8
6.3 -> 赢 8.1
这是行不通的,因为随着 Windows 8.1 的发布,GetVersion API 的行为在它为操作系统版本返回的值方面发生了变化。
如何才能正确获取版本?
最佳答案
您可以在 Windows 的注册表中找到该信息。例如,如果您安装了 Windows 8.1 Pro Edition 并执行以下行:
using Microsoft.Win32;
//...
var windowsName= Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\", "ProductName","");
var version= Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\", "CurrentVersion", "");
var build= Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\", "CurrentBuild", "");
您将分别获得 Windows 8.1 Pro
、6.3
和 9600
。
您也可以使用 WMI 获取 Windows 名称,查看此 post 中的答案:
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# 获取操作系统名称 Windows 8.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29194556/