I’d appreciate if someone can help me out with the issue I am stack on.
I wrote a simple program in C# to check if the following key exists
HKEY_CLASSES_ROOT\Installer\UpgradeCodes\product_upgrade_GUID
It returns true on all Windows (if the key exists) except on Windows Server Enterprise 2008 x64 SP2 where it returns System.NullReferenceException although the key exists.
Actually I get NullReferenceException if I try to access any key inside the \Installer registry. It looks like this Installer key is somehow protected.
Same thing happens when trying to access “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UpgradeCodes” key.
The following code should return “HKEY_CLASSES_ROOT\Installer” but it returns NullReferenceException:
RegistryKey rk = Registry.ClassesRoot.OpenSubKey(@"Installer");
return rk.ToString();
Does anyone know any limitations for accessing the Installer Windows registry? (UAC is disabled and user is admin)
Thank you
Most likely you are running a 32 bit process on a 64 bit system and the registry redirector is taking you to the 32 bit view of the registry. Where those keys do not exist.
Your options include:
RegistryViewenumeration. Note that this requires .net 4. For older versions of .net you would need to use p/invoke to read the 64 bit view of the registry from a 32 bit process.