I am developing VC++ Project. It is a 32-bit application. In Prerequisites check, I am accessing some registry keys/values from this Project. My application is working fine on 32-bit machine. On 64-bit machine, prerequisities check is failing. I am trying to access a registry key under HKLM\SOFTWARE\Microsoft\Microsoft Operations Manager as below:
regKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\RS", true);
On 64-bit machine, the code is checking under HKLM\SOFTWARE\Wow6432Node\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\RS, where the key is not present.
I tried to Disable registry redirection but with no luck. The code for Disbaling Redirection is
Type type = typeof(RegistryKey);
FieldInfo fi = type.GetField("hkey", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Instance);
SafeHandle handle = (SafeHandle)fi.GetValue(regKey);
IntPtr realHandle = handle.DangerousGetHandle();
int errorCode = RegDisableReflectionKey(handle.DangerousGetHandle());