I'm trying to add a registry key (if it doesn't already exist) and have the following code:
RegistrySecurity rs = new RegistrySecurity();
rs.AddAccessRule(new RegistryAccessRule(Environment.UserDomainName + "\\" + Environment.UserName,
RegistryRights.FullControl,
InheritanceFlags.ObjectInherit,
PropagationFlags.InheritOnly,
AccessControlType.Allow));
RegistryKey RK = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION");
if (RK != null)
{
}
else
{
RegistryKey RK1 = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION", RegistryKeyPermissionCheck.ReadWriteSubTree, rs);
RK1.SetValue("TestValue1", "Test.exe", RegistryValueKind.DWord);
}
The problem is that I get an UnauthorisedAccessException at the point at the CreateSubKey line.
Sounds to me like a permissions issue, but I thought the RegistrySecurity took care of it.
Does anyone know what the problem may be?