Discussion in 'ASP .Net Security' started by Darko Bazulj, Jun 4, 2008.

  1. Darko Bazulj

    Darko Bazulj Guest


    how to clear DACL from folder/file?

    I want to achive next:

    I want to clear DACL and add ACEs to ACL and 'stop inheritance'(this work).
    But when I do that "Everyone" ACEs are added to ACL so I need to remove
    "Everyone" ACE from ACL.

    I now do next but is there maybe some better way?

    To remove 'Everyone' I use 'RemoveAccessRuleAll'.


    Sub Main()

    SetInheritance("C:\tmp\ntfs\test", True, False)

    End Sub

    Sub ClearDACL(ByVal strFolderName As String)

    Dim dInfo As New DirectoryInfo(strFolderName)
    Dim dSecurity As DirectorySecurity =

    dSecurity.AddAccessRule(New FileSystemAccessRule("Everyone",
    FileSystemRights.Read, AccessControlType.Allow))


    End Sub

    Sub SetInheritance(ByVal strFolderPath As String, ByVal isProtected As
    Boolean, ByVal preserveInheritance As Boolean)

    Dim dInfo As New DirectoryInfo(strFolderPath)
    Dim dSecurity As DirectorySecurity = dInfo.GetAccessControl()

    dSecurity.SetAccessRuleProtection(isProtected, preserveInheritance)

    End Sub


    Darko Bazulj
    Darko Bazulj, Jun 4, 2008
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.