Forum Discussion

Michl1611's avatar
Michl1611
Occasional Reader
Apr 08, 2026

Configure registry permissions

Hi

I have strange problem to set specific permission to a registry key.

 

According to Microsoft's https://learn.microsoft.com/en-us/dotnet/api/system.security.accesscontrol.registrysecurity?view=net-10.0, it should work like this:

    private static RegistryKey CreateRegistryKey(RegistryKey parentPath) {
        RegistryKey childKey = parentPath.CreateSubKey("myKey");

        RegistryAccessRule rule = new RegistryAccessRule(
            new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null),
            RegistryRights.ReadKey | RegistryRights.Delete,
            InheritanceFlags.ContainerInherit,
            PropagationFlags.None,
            AccessControlType.Allow);
        RegistrySecurity childACL = childKey.GetAccessControl();
        childACL.AddAccessRule(rule);
        ShowSecurity(childACL);
        childKey.SetAccessControl(childACL);

        return childKey;
    }
As I expected

But if the code is executed in a windows service, I missing my permission!?

 

How can this be? Am I doing something wrong? Have I overlooked something?

No RepliesBe the first to reply