Search code examples
.netwindowsregistry32bit-64bit

How do i get the true path to a reg key?


If you are running a 32 bit app on a 64 bit machine (I am using windows 7) and you write this code

RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\XXX")

it will actually get the key from

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\XXX

and not

HKEY_LOCAL_MACHINE\SOFTWARE\XXX

Progromatically given a RegistryKey how do i work out the true path in the registry?


Solution

  • It is very much the True Path, a 32-bit app will always access the registry key in that subkey. Getting the value that a 64-bit app would see is technically possible, just not with .NET. You'll have to P/Invoke RegOpenKeyEx() et al so you can specify the KEY_WOW64_64KEY flag.


    UPDATE: addressed in .NET 4.0 with RegistryKey.OpenBaseKey(). The RegistryView argument lets you specify the view you want. You'd use RegistryView.Registry64 in this case.