system.security.accesscontrol question

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top