public void SetDefault(string name, object value)
{
try
{
GetSetting(name);
}
catch (KeyNotFoundException)
{
SetSetting(name, value);
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(m_rootKey, true))
{
if (m_rootKey.EndsWith(@"\global", StringComparison.CurrentCultureIgnoreCase))
{
System.Security.AccessControl.RegistrySecurity acc = key.GetAccessControl(System.Security.AccessControl.AccessControlSections.All);
System.Security.AccessControl.RegistryAccessRule authenticated = new System.Security.AccessControl.RegistryAccessRule(
new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.AuthenticatedUserSid, null),
System.Security.AccessControl.RegistryRights.ReadKey,
System.Security.AccessControl.InheritanceFlags.None,
System.Security.AccessControl.PropagationFlags.None,
System.Security.AccessControl.AccessControlType.Allow);
acc.AddAccessRule(authenticated);
key.SetAccessControl(acc);
}
}
}
}