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?
The WOW64 Registry reflector may modify the contents of keys and values during the reflection process to adjust path names, and so on. Because of this, the 32-bit and 64-bit contents may differ. For example, pathnames that contain the system32 registry entry are written as SysWOW64 in the 32-bit section of the registry.
Many of the 32-bit keys have the same names as their 64-bit counterparts, and vice versa. The default 64-bit version of Registry Editor (Regedit.exe) that is included with 64-bit versions of Windows displays both 64-bit keys and 32-bit keys.
The default 64-bit version of Registry Editor (Regedit.exe) that is included with 64-bit versions of Windows displays both 64-bit keys and 32-bit keys. The WOW64 registry redirector presents 32-bit programs with different keys for 32-bit program registry entries.
I'm not sure what possibilities Wise gives you regarding scripting, but the way to access the 64-bit registry from a regular program is to use KEY_WOW64_64KEY when manipulating the registry. If it's a possibility to at the least run an external EXE file from the setup, it should solve your problem. Show activity on this post.
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.
Since there is very little documentation about OpenBaseKey
, I'll expand on shifuimam's answer and provide a solution for the OP:
Private Sub Foo()
Dim myAppIs64Bit = Environment.Is64BitProcess
Dim baseKey As RegistryKey
If (myAppIs64Bit) Then
baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)
Else
baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)
End If
Dim myAppKey As RegistryKey = baseKey.OpenSubKey("SOFTWARE\MyApp")
End Sub
If the app is 32-bit, myAppKey
points to HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\MyApp
. If 64-bit, it points to HKEY_LOCAL_MACHINE\SOFTWARE\MyApp
.
The advantage of OpenBaseKey
is that it eliminates the need to reference Wow6432
in your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With