Inside and Out…

An attempt to understand technology better…

SetAccessRuleProtection and Inherited NTFS Permissions

Posted by Gaurav Khanna on July 12, 2005

Continuing from my last post, the same can be achieved using SetAccessRuleProtection as shown below:

using System;
using System.Collections.Generic;
using System.Text;
using System.Security.AccessControl;
using System.IO;
using System.Security.Principal;

namespace AceInheritRemove
{
    class Program
    {
        static void Main(string[] args)
        {
            // Get the object and its SecDescp 
            DirectoryInfo dir = new DirectoryInfo("e:\\kgk\\test");
            DirectorySecurity sec = dir.GetAccessControl(AccessControlSections.All);

            sec.SetAccessRuleProtection(true, false);

            // Create a child folder with the explicit permissions only... 
            DirectoryInfo info2 = new DirectoryInfo("e:\\kgk\\Test\\Child");
            info2.Create(sec);

            dir.SetAccessControl(sec);
        }
    }
}

Advertisements

One Response to “SetAccessRuleProtection and Inherited NTFS Permissions”

  1. protectionspecialties…

    SetAccessRuleProtection and Inherited NTFS Permissions « Inside and Out……

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: