0

I am experiencing a strange inconsistency when trying to read the registry but only affecting Windows 2008 SBS x64 Operating systems. Althought I haven't tried everything but Windows 7 x64 works

Taking the comments aside that I should not be using Wow6432Node in my code at all (I have now changed my production code accordingly), the following seems strange:

Dim baseKey As RegistryKey
Dim regKey As RegistryKey

baseKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64)
regKey = baseKey.OpenSubKey("SOFTWARE", False)
regKey = regKey.OpenSubKey("Wow6432Node", False)
regKey = regKey.OpenSubKey("Parker Technologies", False)
regKey = regKey.OpenSubKey("CaptureIT", False)
regKey = regKey.OpenSubKey("3.0", False)
'the above all opens ok on both windwows 7 x64 and 2008 SBS x64

regKey = baseKey.OpenSubKey("SOFTWARE\Wow6432Node\Parker Technologies", False)
'this opens ok on win 7 x64 but fails to open the key on 2008 SBS x64 
'(although it does exist as it has just been opened above)

Can someone shed any light on why this behaviour is different in windows7 vs SBS?

Matt Wilko
  • 26,994
  • 10
  • 93
  • 143

1 Answers1

1

The most likely explanation is that you have a 32 bit process and so registry redirection is in play. This will redirect you to the Wow6432Node section and then your subsequent redirection results in the key not being found.

You should never hard code Wow6432Node into your app. Use the redirector, it's your friend. If you have to specify a particular view of the registry use the .net 4 RegistryView enumeration. Using the RegistryView enumeration will ensure that the correct location is used no matter whether your process is 32 or 64 bits.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Yes the process is 32 bit. Maybe (Probably/Very Likely) redirection is in play, but why doesn't this happen on my windows 7 x64 machine? – Matt Wilko Dec 22 '11 at 14:39
  • Actually it would appear that it is **not** being redirected on the SBS machine because if I open in Registry64 view and don't specify the Wow6432Node then it still can't find the key – Matt Wilko Dec 22 '11 at 14:55
  • Point taken - I have amended my code but I am still curious about why this is happening in the first place. – Matt Wilko Dec 22 '11 at 16:41
  • I'm not sure about the question you ask in the edit. I find it a little hard to get motivated by though because you simply should not be writing `Wow6432Node` at all. Of course, in the real code you would use `RegistryView.Registry32` to get at this particular key. – David Heffernan Dec 22 '11 at 20:58