How do I change a file's owner to Everyone
and also allow the Everyone
object Full Access
?
Are there any APIs available for this? Do I have to use P/Invoke?
I searched everywhere but can't find anything to do this.
Indeed, there are API's available for this. You may want to have a look at the File.SetAccessControl method in the System.IO namespace.
// Read the current ACL details for the file
var fileSecurity = File.GetAccessControl(fileName);
// Create a new rule set, based on "Everyone"
var fileAccessRule = new FileSystemAccessRule(new NTAccount("", "Everyone"),
FileSystemRights.FullControl,
AccessControlType.Allow);
// Append the new rule set to the file
fileSecurity.AddAccessRule(fileAccessRule);
// And persist it to the filesystem
File.SetAccessControl(fileName, fileSecurity);
The forementioned article has tons of great things to play with, regarding the ACL.
You can use FileInfo.GetAccessControl
and File.SetAccessControl
methods
check the sample code given in MSDN link for File.SetAccessControl
来源:https://stackoverflow.com/questions/17763570/change-a-files-acl-to-allow-full-access-for-everyone