7

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?

Boris
  • 5,094
  • 4
  • 45
  • 71

2 Answers2

7

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

Community
  • 1
  • 1
Robert
  • 39,162
  • 17
  • 99
  • 152
4

try "Everyone" which is a system account defined on every machine or even on the AD domain if any (DOMAIN\Everyone in that case)

VdesmedT
  • 9,037
  • 3
  • 34
  • 50