Advertisement
lorond

Untitled

Apr 16th, 2012
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Security.AccessControl;
  4.  
  5. namespace secur
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Console.Write("path > ");
  12.             var path = Console.ReadLine();
  13.  
  14.             const string usr = @"domain\user";
  15.             SetPermissions(path, usr);
  16.         }
  17.  
  18.         public static void SetPermissions(string folderPath, string domainAndUsername)
  19.         {
  20.             var ds = Directory.GetAccessControl(folderPath);
  21.             var fsac = new FileSystemAccessRule(domainAndUsername,
  22.                                                 FileSystemRights.FullControl,
  23.                                                 InheritanceFlags.ObjectInherit,
  24.                                                 PropagationFlags.InheritOnly,
  25.                                                 AccessControlType.Deny);
  26.  
  27.             ds.AddAccessRule(fsac);
  28.             Directory.SetAccessControl(folderPath, ds);
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement