Windows 2008 SBS x64 Registry Access Strange Behaviour

203 Views Asked by At

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?

1

There are 1 best solutions below

4
On

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.