简体   繁体   English

如何在不继承父项权限的情况下向现有注册表项分配新权限(ACL)

[英]How to assign new rights (ACL) to existing registry key without inheriting rights from parent

New rights can be set using RegistryKey.SetAccessControl(new RegistrySecurity(...)) . 可以使用RegistryKey.SetAccessControl(new RegistrySecurity(...))设置新权限。 But after that the inheritance is turned on . 但是之后inheritance is turned on

Is there a way to assign new rights without turning the inheritance on? 有没有一种方法可以在不打开继承的情况下分配新权限?

The whole code: 整个代码:

void test
{

    SecurityIdentifier sidAccUser = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null);
    NTAccount ntAccUser = sidAccUser.Translate(typeof(NTAccount)) as NTAccount;

    RegistryAccessRule regAcRule = new RegistryAccessRule(
      ntAccUser
    , RegistryRights.FullControl
    , InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit
    , PropagationFlags.None
    , AccessControlType.Allow);

    RegistrySecurity regSecurity = new RegistrySecurity();
    regSecurity.AddAccessRule(regAcRule);

    RegistryKey regKey = Registry.CurrentUser.OpenSubKey(@"ZZTEST", true);

    // after that the inheritance is turned on
    regKey.SetAccessControl(regSecurity);

}

I found this solution but don't want to use a COM-Server: Setting permissions and blocking inheritance from C# with SetACL 我找到了此解决方案,但不想使用COM服务器: 使用SetACL设置权限并阻止从C#继承

Use SetAccessRuleProtection to protect the DACL from inheritance.. 使用SetAccessRuleProtection保护DACL免受继承。

regSecurity.SetAccessRuleProtection(true, false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM