When calling OpenSubKey from C# application, getting Security Exception error and the application is not launching

  • Thread starter Thread starter Satyaprakash A
  • Start date Start date
S

Satyaprakash A

Guest
Hello All,

When calling OpenSubKey Registry function from the C# application, getting the below exception and because of this application is not launching.

Application: EMR.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.Security.SecurityException at System.ThrowHelper.ThrowSecurityException(System.ExceptionResource) at Microsoft.Win32.RegistryKey.OpenSubKey(System.String, Boolean)

Below is the Registry key value passing into the openSubkey
HKEY_LOCAL_MACHINE\SOFTWARE\EMR\4.01.00\Technical Data

And one more thing is, after installation first time I am able to launch the application. But Once restart the machine then when trying to launch I am seeing this error.

Below is the code snippet:

public RegistryKey GetRegKeyHandle(String key)

{

key = BASE_REG_KEY + "\\" + key;

if (MainFrame.GetUIControlObject().MGDIsAdmin())
{
MessageBox.Show("Entered to MGDIsAdmin");
regWritable = true;
RegistryKey rkTest = Registry.LocalMachine.OpenSubKey(key, true);

return rkTest;
}
else
{
return Registry.LocalMachine.OpenSubKey(key);
}
}

Please help me why it is throwing security exception only after restart?

Continue reading...
 
Back
Top