Reading the registry and Wow6432Node key

Jade M picture Jade M · Jan 11, 2010 · Viewed 70.7k times · Source

I have some code that reads the registry and looks for a value in HKEY_LOCAL_MACHINE\Software\App\ but when running on 64-bit versions of Windows the value is under HKEY_LOCAL_MACHINE\Software\Wow6432Node\App\.

How should I best approach this? Do I need a 64-bit installer or should I rewrite my code to detect both places?

Answer

Wallace Kelly picture Wallace Kelly · Sep 12, 2013

On an x64 machine, here is an example of how to access the 32-bit view of the registry:

using (var view32 = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser,
                                            RegistryView.Registry32))
{
  using (var clsid32 = view32.OpenSubKey(@"Software\Classes\CLSID\", false))
  {
    // actually accessing Wow6432Node 
  }
}

... as compared to...

using (var view64 = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser,
                                            RegistryView.Registry64))
{
  using (var clsid64 = view64.OpenSubKey(@"Software\Classes\CLSID\", true))
  {
    ....
  }
}