Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create 64 bit registry key (non-WOW64) from a 32 bit application

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?

like image 800
James Newton-King Avatar asked Feb 04 '10 03:02

James Newton-King


People also ask

Why are the 32-bit and 64-bit contents of the WOW64 registry different?

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.

What is the difference between 32 bit and 64 bit registry keys?

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.

Is Registry Editor 32 bit or 64 bit?

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.

How do I access the 64-bit registry?

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.


2 Answers

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.

like image 189
ClairelyClaire Avatar answered Sep 26 '22 02:09

ClairelyClaire


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.

like image 34
nunzabar Avatar answered Sep 26 '22 02:09

nunzabar