C# 获取操作系统名称 Windows 8.1

标签 c# operating-system

我想检查运行的窗口是 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 Pro6.39600

您也可以使用 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/

相关文章:

c# - ExcelDataReader for C# 是否需要在目标计算机上安装 Excel?

c# - 让我们加密 API 不返回根证书?

c# - C# 中的 if(a==5) 或 if(5==a) 之间有什么区别吗?

c# - EF Code First 比较空值会生成奇怪的查询

c# - 在 ASP.NET Core 中使用 ConfigureAppConfiguration 方法进行日志记录

php - 文件检查函数总是 "ignore"前导斜杠

java - 错误 : could not find libjava. 所以,错误:找不到 Java 2 运行时环境

node.js - 如何跨平台移动 npm node_modules 文件夹?

linux - 自定义 Linux 图形用户界面

c++ - "const char far* inStrSource"是什么意思?