D
Darko Bazulj
Hi,
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()
ClearDACL("C:\tmp\ntfs\test")
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 =
dInfo.GetAccessControl(AccessControlSections.None)
dSecurity.AddAccessRule(New FileSystemAccessRule("Everyone",
FileSystemRights.Read, AccessControlType.Allow))
dInfo.SetAccessControl(dSecurity)
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)
dInfo.SetAccessControl(dSecurity)
End Sub
#########
Regards,
Darko Bazulj
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()
ClearDACL("C:\tmp\ntfs\test")
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 =
dInfo.GetAccessControl(AccessControlSections.None)
dSecurity.AddAccessRule(New FileSystemAccessRule("Everyone",
FileSystemRights.Read, AccessControlType.Allow))
dInfo.SetAccessControl(dSecurity)
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)
dInfo.SetAccessControl(dSecurity)
End Sub
#########
Regards,
Darko Bazulj