The tool I develop needs to grant access rights \"Full Control\" to a file created by it. It needs to be read, modified and deleted from all windows accounts and even possib
You will need to give full control to "Everyone" group on the machine. Found this post on MSDN which talks about it.
Hope this works for you.
Note to people using this.
When using literal strings for the FileSystemAccessRule
, it should be WellKnownSidType.WorldSid
instead of "everyone"
.
The reason is because there are multiple Window languages and Everyone only applies to EN ones, so for Spanish, it might be "Todos" (or something else).
using System.Security.AccessControl;
using System.Security.Principal;
using System.IO;
private void GrantAccess(string fullPath)
{
DirectoryInfo dInfo = new DirectoryInfo(fullPath);
DirectorySecurity dSecurity = dInfo.GetAccessControl();
dSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.NoPropagateInherit, AccessControlType.Allow));
dInfo.SetAccessControl(dSecurity);
}