How to provide full permission to the file created by my application for ALL users?

The tool that I am developing should provide Full Control access rights to the file created by him. It must be read, modified, and deleted from all Windows accounts and even possible future accounts. Could this be achieved?

I know I can try this for SPECIFIC_USER:

FileSystemAccessRule rule = new FileSystemAccessRule(SPECIFIC_USER, FileSystemRights.FullControl, AccessControlType.Allow); FileSecurity fSecurity = File.GetAccessControl(filePath); fSecurity.SetAccessRule(rule); File.SetAccessControl(filePath, fSecurity); 

But how can I provide it to all users? And even possible future bills? If the last part is not possible, how to fulfill the first requirement?

Thank.

EDIT:

This is the code that worked for me. Taken from the defendant’s link.

 private bool GrantAccess(string fullPath) { DirectoryInfo dInfo = new DirectoryInfo(fullPath); DirectorySecurity dSecurity = dInfo.GetAccessControl(); dSecurity.AddAccessRule(new FileSystemAccessRule("everyone", FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.NoPropagateInherit, AccessControlType.Allow)); dInfo.SetAccessControl(dSecurity); return true; } 

Note the PropagationFlags.NoPropagateInherit , which is required (indicated at the end in the link). This gives privileges even to future accounts.

+53
c # winforms permissions user-accounts
Feb 02 '12 at 7:10
source share
2 answers

Note to people using this.

When using literal strings for FileSystemAccessRule it should be WellKnownSidType.WorldSid instead of "everyone" .

The reason is that there are several Window languages, and all apply only to the EN, so for the Spanish language it could 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); } 
+91
Apr 25 '13 at 13:51
source share

You will need to fully control the Everyone group on the machine. Found this post on MSDN that talks about it.

Hope this works for you.

+12
Feb 02 '12 at 7:17
source share



All Articles