Search code examples
c#ntfs

retrieve and set NTFS permissions using c#


I m confused how can I retrieve and set the NTFS permission for a directory using c#

such as Save file Stream and save file security

I'm looking for how can I save those properties for an executable so that it's stream cannot be modified.


Solution

  • System.Security.AccessControl.FileSecurity would be the place to start.

    See the example on that page using File.GetAccessControl method to get an instance.

    NB.

    it's stream cannot be modified .

    ACLs can always be overridden (not least my anyone with the Take Ownership privilege: as all local administrators have). If you want to ensure an exe is not modified you would be better looking at code signing.