Manage NTFS permissions with

Posted on 2005-05-04
Last Modified: 2013-12-03
Is there away to manage NTFS permissions from I have looked at ADSI but that doesn't allow you to manage the folder permissions. Is there an API like ADSI the <%@ Import Namespace = "System.DirectoryServices"%>.


Question by:jui2ce
    LVL 10

    Accepted Solution

    Investigate a little more about  this library.

    using Microsoft.Win32.Security;

    Here's a method to add a dir, and set NTFS permissions on it for a given user:

    private Boolean CreateDir(String strSitePath, String strUserName) {

           Boolean bOk;

           try {


                  SecurityDescriptor secDesc = SecurityDescriptor.GetFileSecurity(strSitePath, SECURITY_INFORMATION.DACL_SECURITY_INFORMATION);

                  Dacl dacl = secDesc.Dacl;

                  Sid sidUser = new Sid (strUserName);


                  // allow: folder, subfolder and files

                  // modify

                  dacl.AddAce (new AceAccessAllowed (sidUser, AccessType.GENERIC_WRITE | AccessType.GENERIC_READ | AccessType.DELETE | AccessType.GENERIC_EXECUTE , AceFlags.OBJECT_INHERIT_ACE | AceFlags.CONTAINER_INHERIT_ACE));


                  // deny: this folder

                  // write attribs

                  // write extended attribs

                  // delete

                  // change permissions

                  // take ownership

                  DirectoryAccessType DAType = DirectoryAccessType.FILE_WRITE_ATTRIBUTES | DirectoryAccessType.FILE_WRITE_EA | DirectoryAccessType.DELETE | DirectoryAccessType.WRITE_OWNER | DirectoryAccessType.WRITE_DAC;

                  AccessType AType = (AccessType)DAType;

                  dacl.AddAce (new AceAccessDenied (sidUser, AType));



                  secDesc.SetFileSecurity(strSitePath, SECURITY_INFORMATION.DACL_SECURITY_INFORMATION);

                  bOk = true;

           } catch {

                  bOk = false;


           return bOk;

    } /* CreateDir */

    LVL 20

    Expert Comment

    Unfortunately, before .NET Framework 2.0,  using win32 interop, c# and memory pointers is the only way to go.

    full working code:

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now