DirectoryInfo.SetAccessControl is throwing privilege error

Jan 25, 2012 at 6:33 PM


An excpetion "A required privilege is not held by the client" when the statement directoryInfo.SetAccessControl(directorySecurity) is called.

We do not get this error for exactly the same directory when the Windows DirectoryInfo class is used, it only occurs when those same calls use AlphaFS.

Can anyone please let us know, the solution for this error.





Jan 26, 2012 at 5:22 PM


Could you provide a failing codesample and/or a unit-test for this?


Jan 26, 2012 at 5:58 PM

That call, if you are not running as admin requires SE_SECURITY privilege.

You need to use Alphaleonis.Win32.Security.PrivilegeEnabler. The following is the extra+ example of privs you can use.


using (new Alphaleonis.Win32.Security.PrivilegeEnabler(Alphaleonis.Win32.Security.Privilege.Security, Alphaleonis.Win32.Security.Privilege.Audit, Alphaleonis.Win32.Security.Privilege.Restore, Alphaleonis.Win32.Security.Privilege.Backup, Alphaleonis.Win32.Security.Privilege.TakeOwnership))
      Directory.SetAccessControl(path, bob, AccessControlSections.Access | AccessControlSections.Owner | AccessControlSections.Group);


.NET itself is using the same method seamlessly calling it for a big number of methods behind the scenes, that's why you didn't encounter this error.