string user = @"NT AUTHORITY\NETWORK SERVICE";
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\services\eventlog");
RegistrySecurity regSec = new RegistrySecurity();
RegistryAccessRule rule = new RegistryAccessRule(
user,
RegistryRights.FullControl,
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
PropagationFlags.InheritOnly,
AccessControlType.Allow);
regSec.AddAccessRule(rule);
key.SetAccessControl(regSec);
我收到 System.Unauthorizedaccessexception:“无法写入注册表项。” 在 key.SetAccessControl(regSec);
我以管理员身份运行该应用程序。