Simon
Simon

Reputation: 34830

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?

Upvotes: 0

Views: 200

Answers (2)

Hans Passant
Hans Passant

Reputation: 941257

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.

Upvotes: 1

fupsduck
fupsduck

Reputation: 3189

It is a function of whether or not the program was compiled for 32 or 64 bit Windows and whether it's running on 32 or 64 bit Windows. See if below helps:

http://social.msdn.microsoft.com/Forums/en-US/netfx64bit/thread/92f962d6-7f5e-4e62-ac0a-b8b0c9f552a3

Upvotes: 0

Related Questions