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?
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:
The complete solution is already described in this answer: Add "Everyone" privilege to folder using C#.NET