So I'm trying to make a new folder on the local drive, and grant it with specific permissions. The main ruleset would be: - Admin has complete access - A specific user (let's call it "Robinson") has complete access - The rest of normal users on the computer would have no access to it.
So far I did this with my code:
string path = @"C:\testFolder";
DirectorySecurity ds = Directory.GetAccessControl(path);
SecurityIdentifier si_Admin = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid,null);
ds.AddAccessRule(new FileSystemAccessRule(si_Admin, FileSystemRights.FullControl, AccessControlType.Allow));
ds.AddAccessRule(new FileSystemAccessRule("Robinson", FileSystemRights.FullControl, AccessControlType.Allow));
SecurityIdentifier si_OtherUsers = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null);
ds.AddAccessRule(new FileSystemAccessRule(si_OtherUsers, FileSystemRights.Delete, AccessControlType.Deny));
Directory.SetAccessControl(path, ds);
You might notice that on the 3rd AddAccessRule, i am just testing the waters of removing permissions to the other users. Unfortunately this also denies any Deletion for Admin and Robinson as well...and I ended up with a folder that I cannot delete!
So does anybody know what am I missing? And also how could I solve the unremovable folder situation?
Thanks in advance!