0
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);
註冊表SetAccessControl
我以管理員身份運行應用程序。