views:

872

answers:

2

I have a Visual Studio installer that is creating some registry keys:

HKEY_LOCAL_MACHINE\SOFTWARE\MyApp

but the registry keys it is creating are automatically appearing under Wow6432Node:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\MyApp

How do I ignore the Wow6432Node when creating registry keys in my C# code being executed by the msi?

+1  A: 

Take a look at http://www.pinvoke.net/default.aspx/advapi32/regopenkeyex.html. You'll need to use the registry redirector and pass in the proper value for the access mask. Unfortunately you'll need pInvoke.

nithins
Oh fantastic. Is there any nice .NET API around that someone has written to wrap the pinvoke calls and make it not so terrible?
James Newton-King
I wouldn't say it's that terrible really. A bit inconvenient perhaps. Just add the DllImports and define KEY_WOW64_64KEY. A more concise example (for deletion) can be found on http://geekswithblogs.net/derekf/archive/2007/06/26/113485.aspx.
nithins
+3  A: 

Just FYI, .NET 4.0 supports this natively. Example:

RegistryBase = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);

You can then use that RegistryBase variable to access anything in the 64-bit view of HKLM. Conversely, Registry32 will let a 64-bit application access the 32-bit view of the registry.

shifuimam
great answer. simple and to the point.
Simon