返回了错误的 OS 版本详细信息
Wrong OS Version Details are returned
我想在 C# .NET 代码中获取基础机器 OS 信息及其其他详细信息。
当 运行 以下代码在 Windows 10 Pro 机器上时,returns 错误值为“Windows 10 Enterprise”。
Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName", "").ToString();
Registry上还有其他键值可以查询吗?否则它已经通过其 次要版本和主要版本 详细信息进行了手动解释?
根据您的系统,它需要在 32 位或 64 位注册表上明确查询。
此解决方案不使用任何 hack 来获取 OS 版本。当您导航到该路径时,它提供的值与您在注册表中看到的值完全相同。
例如。在我的例子中是 returns, "Windows 10 Pro"
RegistryKey localKey = null;
if (Environment.Is64BitOperatingSystem) {
localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine,
RegistryView.Registry64);
} else {
localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine,
RegistryView.Registry32);
}
var productName = localKey.OpenSubKey(@ "SOFTWARE\Microsoft\Windows
NT\CurrentVersion").GetValue("ProductName").ToString();
Console.WriteLine("ProductName : " + productName);
我想在 C# .NET 代码中获取基础机器 OS 信息及其其他详细信息。
当 运行 以下代码在 Windows 10 Pro 机器上时,returns 错误值为“Windows 10 Enterprise”。
Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName", "").ToString();
Registry上还有其他键值可以查询吗?否则它已经通过其 次要版本和主要版本 详细信息进行了手动解释?
根据您的系统,它需要在 32 位或 64 位注册表上明确查询。
此解决方案不使用任何 hack 来获取 OS 版本。当您导航到该路径时,它提供的值与您在注册表中看到的值完全相同。
例如。在我的例子中是 returns, "Windows 10 Pro"
RegistryKey localKey = null;
if (Environment.Is64BitOperatingSystem) {
localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine,
RegistryView.Registry64);
} else {
localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine,
RegistryView.Registry32);
}
var productName = localKey.OpenSubKey(@ "SOFTWARE\Microsoft\Windows
NT\CurrentVersion").GetValue("ProductName").ToString();
Console.WriteLine("ProductName : " + productName);