Create an accessible directory accessible only to the administrator

I have an administrator application that works with elevated privileges, and I need it to store some confidential files in a directory that only system administrators can access.

This is probably due to the next call, but I'm not sure how to configure it.

Directory.CreateDirectory(@"C:\SomePath", new AccessControl.DirectorySecurity() { AccessRightType = ?, AccessRuleType = ?, AuditRuleType = ?);

If there is a better way to achieve the same, please let me know. Thank.

EDIT: Found a good implementation here . Leave the question open for one day if there are other suggestions.

+5
source share
1 answer

Found a good solution here .

FileSystemAccessRule administratorRule = new FileSystemAccessRule("Administrators", FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow);

FileSystemAccessRule guestRule = new FileSystemAccessRule("Guest", FileSystemRights.CreateDirectories | FileSystemRights.CreateFiles, AccessControlType.Allow);

DirectorySecurity dirSec = new DirectorySecurity();
dirSec.AddAccessRule(administratorRule);
dirSec.AddAccessRule(guestRule);

Directory.CreateDirectory(@"C:\GuestTemp", dirSec);
+5
source

All Articles