Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Plz help me on programmatically set NTFS file system folder permissions

Plz help me on programmatically set NTFS file system folder permissions

Scheduled Pinned Locked Moved C#
helpcsharpwindows-adminsecurity
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sanjib Raj
    wrote on last edited by
    #1

    i have programmatically set NTFS file system folder permissions by using Active Directory Service Interfaces in Microsoft Visual C#.the problem is that i give permissions through Mohana//administrator(Domin/User) to (C:\\Test) Folder. the program works but when i right click the test folder goto Security Tab it create another user (BUILTIN//BUILTIN)and give All permition to it. i want all permission to administrator. Plz help me. ...code.... using System; using System.Security; using ADSSECURITYLib; using ActiveDs; namespace SecurityFolder { public class clsSecurity { public clsSecurity() { } public void preformAction() { // Set to your domain name. // Set to the user account. SetPermissions("C:\\Test","MOHANA\\administrator"); Console.WriteLine ("Full Access control granted."); } public void SetPermissions(string vPath, String UserName ) { ADsSecurity objADsSec; SecurityDescriptor objSecDes; AccessControlList objDAcl; AccessControlEntry objAce1; AccessControlEntry objAce2; Object objSIdHex; ADsSID objSId; string mes; objADsSec = new ADsSecurityClass(); objSecDes = (SecurityDescriptor)(objADsSec.GetSecurityDescriptor("FILE://"+vPath)); //objSecDes=(SecurityDescriptor)objADsSec.GetSecurityDescriptor(vPath); objDAcl = (AccessControlList)objSecDes.DiscretionaryAcl; objSId = new ADsSIDClass(); objSId.SetAs((int)ADSSECURITYLib.ADS_SID_FORMAT.ADS_SID_SAM, UserName.ToString()); objSIdHex = objSId.GetAs((int)ADSSECURITYLib.ADS_SID_FORMAT.ADS_SID_SDDL); // Add a new access control entry (ACE) object (objAce) so that the user has Full Control permissions on NTFS file system files. objAce1 = new AccessControlEntryClass(); objAce1.Trustee = System.Convert.ToString (objSIdHex); objAce1.AccessMask = (int)ActiveDs.ADS_RIGHTS_ENUM.ADS_RIGHT_GENERIC_ALL; objAce1.AceType = (int)ActiveDs.ADS_ACETYPE_ENUM.ADS_ACETYPE_ACCESS_ALLOWED; objAce1.AceFlags = (int)ActiveDs.ADS_ACEFLAG_ENUM.ADS_ACEFLAG_INHERIT_ACE | (int)ActiveDs.ADS_ACEFLAG_ENUM.ADS_ACEFLAG_INHERIT_ONLY_ACE | 1; objDAcl.AddAce(objAce1); // Add a new access control entry object (objAce) so that the user has Full Control permissions on NTFS file system folders. objAce2 = new AccessControlEntryClass(); objAce2.Trustee = System.Convert.ToString (objSIdHex); objAce2.AccessMask = (int)ActiveDs.ADS_RIGHTS_ENUM.ADS_RIGHT_GENERIC_ALL; objAce2.AceType = (int)ActiveDs.

    B 1 Reply Last reply
    0
    • S Sanjib Raj

      i have programmatically set NTFS file system folder permissions by using Active Directory Service Interfaces in Microsoft Visual C#.the problem is that i give permissions through Mohana//administrator(Domin/User) to (C:\\Test) Folder. the program works but when i right click the test folder goto Security Tab it create another user (BUILTIN//BUILTIN)and give All permition to it. i want all permission to administrator. Plz help me. ...code.... using System; using System.Security; using ADSSECURITYLib; using ActiveDs; namespace SecurityFolder { public class clsSecurity { public clsSecurity() { } public void preformAction() { // Set to your domain name. // Set to the user account. SetPermissions("C:\\Test","MOHANA\\administrator"); Console.WriteLine ("Full Access control granted."); } public void SetPermissions(string vPath, String UserName ) { ADsSecurity objADsSec; SecurityDescriptor objSecDes; AccessControlList objDAcl; AccessControlEntry objAce1; AccessControlEntry objAce2; Object objSIdHex; ADsSID objSId; string mes; objADsSec = new ADsSecurityClass(); objSecDes = (SecurityDescriptor)(objADsSec.GetSecurityDescriptor("FILE://"+vPath)); //objSecDes=(SecurityDescriptor)objADsSec.GetSecurityDescriptor(vPath); objDAcl = (AccessControlList)objSecDes.DiscretionaryAcl; objSId = new ADsSIDClass(); objSId.SetAs((int)ADSSECURITYLib.ADS_SID_FORMAT.ADS_SID_SAM, UserName.ToString()); objSIdHex = objSId.GetAs((int)ADSSECURITYLib.ADS_SID_FORMAT.ADS_SID_SDDL); // Add a new access control entry (ACE) object (objAce) so that the user has Full Control permissions on NTFS file system files. objAce1 = new AccessControlEntryClass(); objAce1.Trustee = System.Convert.ToString (objSIdHex); objAce1.AccessMask = (int)ActiveDs.ADS_RIGHTS_ENUM.ADS_RIGHT_GENERIC_ALL; objAce1.AceType = (int)ActiveDs.ADS_ACETYPE_ENUM.ADS_ACETYPE_ACCESS_ALLOWED; objAce1.AceFlags = (int)ActiveDs.ADS_ACEFLAG_ENUM.ADS_ACEFLAG_INHERIT_ACE | (int)ActiveDs.ADS_ACEFLAG_ENUM.ADS_ACEFLAG_INHERIT_ONLY_ACE | 1; objDAcl.AddAce(objAce1); // Add a new access control entry object (objAce) so that the user has Full Control permissions on NTFS file system folders. objAce2 = new AccessControlEntryClass(); objAce2.Trustee = System.Convert.ToString (objSIdHex); objAce2.AccessMask = (int)ActiveDs.ADS_RIGHTS_ENUM.ADS_RIGHT_GENERIC_ALL; objAce2.AceType = (int)ActiveDs.

      B Offline
      B Offline
      bobsugar222
      wrote on last edited by
      #2

      DirectoryInfo di = new DirectoryInfo("C:\\TestDir");
      DirectorySecurity dc = new DirectorySecurity();
      FileSystemAccessRule ar = new FileSystemAccessRule("Administrator",FileSystemRights.FullControl,AccessControlType.Allow);
      dc.AddAccessRule(ar);
      di.Create(dc);

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups