1

我可以使用 C# 从注册表中读取 Windows“产品名称”

Registry.GetValue ( @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName", "" )

我正在运行 64 位版本的 Windows Pro,但在 32 位应用程序中,这将返回“Windows 10 Enterprise”。

事实上,如果我查看注册表,我可以在键中看到

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion

值为“Windows 10 Pro”,但在键中

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion

它是“Windows 10 企业版”。

这有道理吗?

有没有一种简单(即一行)的方法来获取真实的产品名称?

4

2 回答 2

0

我不知道为什么 32 位和 64 位配置单元不同。在我全新安装的 Windows 10 Pro x64 21H1 中,32 位版本具有Editionof"Enterprise"ProductNameof "Windows 10 Enterprise"。64 位注册表具有正确的"Pro"值。

我的 32 位进程默认为 x64 操作系统上的 32 位注册表。如果代码确实在 32 位操作系统上运行,我想介绍一下这种情况。

它不是单行的,但我使用此代码根据操作系统选择注册表。

var hklm64 = RegistryKey.OpenBaseKey(
  RegistryHive.LocalMachine,
  Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32
);

RegistryKey rk = hklm64.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");

string product = (string)rk.GetValue("ProductName");
string edition = (string)rk.GetValue("Edition");
于 2021-07-06T18:55:39.420 回答
0

只要您不想支持 Windows Vista 之前的操作系统版本,就可以使用GetProductInfo 。

于 2021-04-07T07:05:14.997 回答