I'm trying to modify some of the permissions on a file for the current users account (i.e. I'm currently debugging this, so my account).
In case it helps, my user shows up as FirstName LastName (email@domain)
in the Properties > Security window.
I've tried the following, but can't seem to get the right one. I kinda feel like I'm just taking random shots in the dark at this point... Neither rule 1 nor rule2 work, any the rest of the Sids don't stand out as being the correct one to me, but I'm hoping I'm overlooking something.
public static void AddUserPermission(string filePath)
{
FileSecurity fs = File.GetAccessControl(filePath);
//This adds a "Domain Users" group...
FileSystemAccessRule rule1 = new FileSystemAccessRule(
new SecurityIdentifier(WellKnownSidType.AccountDomainUsersSid, WindowsIdentity.GetCurrent().User.AccountDomainSid), FileSystemRights.Modify, AccessControlType.Deny);
//Adds a "BUILTIN" group...
FileSystemAccessRule rule2 = new FileSystemAccessRule(
new SecurityIdentifier(WellKnownSidType.BuiltinDomainSid, null), FileSystemRights.Modify, AccessControlType.Deny);
fs.AddAccessRule(rule1);
fs.AddAccessRule(rule2);
File.SetAccessControl(filePath, fs);
}