How can I set up a file for recording by all users?

I want the file to be writable 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 do not know which line to use. I tried users = WindowsAccountType.Normal.ToString() , but this only gives "Normal" , which does not work. How can I get a string that represents the group of all users on the machine?

+7
source share
2 answers

I assume that you are looking for the Everyone group, to which all registered users belong. However, using the "Everyone" line will cause serious problems with non-English systems.

Best used with SecurityIdentifier WellKnownSidType.WorldSid:

 SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null); 

The complete solution is already described in this answer: Add the "All" privilege to the folder using C # .NET

+7
source

try "Everything", which is the system account defined on each computer or even in the AD domain, if there is one (DOMAIN \ Everyone in this case)

+4
source

All Articles