0

Possible Duplicate:
C# WOW6432 registry node messin things up

This is the code:

var b1 = Registry.LocalMachine.OpenSubKey("software", true); 
var b2 = Registry.LocalMachine.OpenSubKey("software", true).OpenSubKey("company");
var r1 = Registry.LocalMachine.OpenSubKey("software").OpenSubKey("company").GetValueNames();
string resultString = Registry.LocalMachine.OpenSubKey("Software", true).CreateSubKey("company").GetValue(name).ToString();

I invoke it with name = "ApplicationDirectory". At the last line, the first two variables point to the correct locations (based on their Name property). The problem is with r1, which doesn't list the contents of HKEY_LOCAL_MACHINE\SOFTWARE\company, but rather HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\company. Why is this? Is this some redirection in 64-bit machines?

Community
  • 1
  • 1
bossmann
  • 49
  • 1
  • 4

1 Answers1

2

Yes, there is a redirection for 32-bit applications on 64-bit machines. See comments on your question, and also this SO answer.

If you target .Net 4 or above, you'll be able to access both Wow6432Node (used for 32-bit applications) and "standard" node (the one used for 64-bit applications) as RegistryKey.OpenBaseKey method provides a parameter of type RegistryView that allows choosing the correct node to use.

If you're using .Net 3.5 or previous version, then you'll have to use P/Invoke if you want to be able to read both 32/64 bit registry keys on a 64-bit machine. You'll have to use RegOpenKeyEx and specify KEY_WOW64_32KEY as flag for desired access. But this is another story and out of the scope of your question.

Community
  • 1
  • 1
ken2k
  • 48,145
  • 10
  • 116
  • 176