I want to set a file to be writeable by all users.
FileSecurity sec = File.GetAccessControl(fileName);
string users = ?????;
sec.AddAccessRule(new FileSystemAccessRule(
users,
FileSystemRights.Write,
AccessControlType.Allow));
File.SetAccessControl(fileName, sec);
The problem is that I don't know which string to use. I have tried users = WindowsAccountType.Normal.ToString()
, but that only gives "Normal"
, which doesn't work. How can I get the string that designates the group of all users on a machine?
Change file permissions To change file and directory permissions, use the command chmod (change mode). The owner of a file can change the permissions for user ( u ), group ( g ), or others ( o ) by adding ( + ) or subtracting ( - ) the read, write, and execute permissions.
To give the owner all permissions and world execute you would type chmod 701 [filename]. To give the owner all permissions and world read and execute you would type chmod 705 [filename].
I assume you are looking for the "Everyone" group which all logged-on users belong to. However using the string "Everyone" will get you into serious trouble on non-english systems
A much better solution is to use it via SecurityIdentifier WellKnownSidType.WorldSid:
SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
The complete solution is already described in this answer: Add "Everyone" privilege to folder using C#.NET
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With