18

I have an issue where I need to add give access to a folder for all authenticated users to store application related settings. I have found that this can be done with the below code...

var Info = new DirectoryInfo(settingsdir);
var Security = Info.GetAccessControl(AccessControlSections.Access);

Security.AddAccessRule(
    new FileSystemAccessRule(
        "Authenticated Users", FileSystemRights.Modify,
        InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
        PropagationFlags.None,
        AccessControlType.Allow));

The problem I have found is that "Authenticated Users" is a system account that is on windows however, on different language versions of Windows this account name is translated, for instance in Germany this account is called 'Authentifizierte Benutzer'. Is there a way to know the proper name of this account (with out the obvious of going through every language and finding the correct account name).

rae1
  • 6,066
  • 4
  • 27
  • 48
Matthew Sanford
  • 1,069
  • 1
  • 13
  • 21

1 Answers1

32

I'd suggest you use the Well Known SID list (see http://support.microsoft.com/kb/243330). Authenticated User is always SID: S-1-5-11. If you use that, it ought to be language agnostic (but I've not tested).

Create a SecurityIdentifier and use that instead:

var sid = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null); 

Security.AddAccessRule(
   new FileSystemAccessRule(
       sid,
       FileSystemRights.Modify,
       InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
       PropagationFlags.None,
       AccessControlType.Allow));
Zeus82
  • 6,065
  • 9
  • 53
  • 77
Grhm
  • 6,726
  • 4
  • 40
  • 64
  • 1
    Worked for me too but I had to call `Info.SetAccessControl(Security)` to commit the changes as described here: http://stackoverflow.com/questions/8944765/c-sharp-set-directory-permissions-for-all-users-in-windows-7 – Johan Gov Feb 24 '15 at 13:36
  • AddAccessRule or *ModifyAccessRule* ? – Kiquenet May 30 '19 at 19:10