如何打开从64位.NET应用程序一个WOW64注册表项注册表、应用程序、NET

2023-09-02 11:47:44 作者:ぐ懵懂少年恋go

我的.NET应用程序(任何-CPU)需要读取由32位程序创建的注册表值。在64位的Windows这正好下在注册表中的Wow6432Node关键。我已阅读,你不应该硬code到Wow6432Node,所以什么是正确的方式来使用.NET访问它?

My .NET application (any-CPU) needs to read a registry value created by a 32-bit program. On 64-bit Windows this goes under the Wow6432Node key in the registry. I have read that you shouldn't hard-code to the Wow6432Node, so what's the right way to access it with .NET?

推荐答案

在那里你明确需要读取写的32位程序的值在64位程序的情况下,它的确定到c很难$ C $。很简单,因为实在是没有其他选择。

In the case where you explicitly need to read a value written by a 32 bit program in a 64 bit program, it's OK to hard code it. Simply because there really is no other option.

我当然会抽象出来给一个辅助功能。例如

I would of course abstract it out to a helper function. For example

public RegistryKey GetSoftwareRoot() {
  var path = 8 == IntPtr.Size 
    ? @"SoftwareWow6432Node"
    : @"Software";
  return Registry.CurrentUser.OpenSubKey(path);
}