A
A
aeaeae12022-02-08 04:12:55
C++ / C#
aeaeae1, 2022-02-08 04:12:55

How to remove bans for the System c# group?

Good afternoon, how to remove system restrictions?

String path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            String filePath = Path.Combine(path, "temp3");
           
            DirectorySecurity sec = Directory.GetAccessControl(filePath);

            SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.BuiltinDomainSid, null);
            string permissionShort = string.Empty;
            
            foreach (FileSystemAccessRule rule in  sec.GetAccessRules(true, true, typeof(NTAccount)))
            {
                if (rule.AccessControlType == AccessControlType.Deny)
                    permissionShort += ((rule.FileSystemRights & FileSystemRights.WriteData) == FileSystemRights.WriteData) ? "NotAccess" : "Access";
           if ( permissionShort== "NotAccess")
           {
           sec.RemoveAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.WriteData, AccessControlType.Deny));

           }
                Console.WriteLine(permissionShort);
                Console.ReadLine();

            }

I am writing a code in which I need to make sure that if there is a ban, it will be deleted.
6201c4741fd5e116237873.png

SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.BuiltinDomainSid, Tried the options here but which one is responsible for the system group?

Tried that also no change
System.Security.Principal.NTAccount group = new System.Security.Principal.NTAccount("SYSTEM");
sec.RemoveAccessRule(new FileSystemAccessRule(group, FileSystemRights.WriteData, AccessControlType.Deny));

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question