为文件夹添加users,everyone用户组的完全控制权限
''' <summary>
'''为文件夹添加users,everyone用户组的完全控制权限
''' </summary>
''' <param name="dirPath"></param>
Private Shared Sub AddSecurityControll2Folder(ByVal dirPath As String)
'获取文件夹信息
Dim dir As New IO.DirectoryInfo(dirPath)
'获得该文件夹的所有访问权限
Dim dirSecurity As System.Security.AccessControl.DirectorySecurity = dir.GetAccessControl(AccessControlSections.All)
'设定文件ACL继承
Dim [inherits] As InheritanceFlags = InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit
'添加ereryone用户组的访问权限规则 完全控制权限
Dim everyoneFileSystemAccessRule As New FileSystemAccessRule("Everyone", FileSystemRights.FullControl, [inherits], PropagationFlags.None, AccessControlType.Allow)
'添加Users用户组的访问权限规则 完全控制权限
Dim usersFileSystemAccessRule As New FileSystemAccessRule("Users", FileSystemRights.FullControl, [inherits], PropagationFlags.None, AccessControlType.Allow)
Dim isModified As Boolean = False
dirSecurity.ModifyAccessRule(AccessControlModification.Add, everyoneFileSystemAccessRule, isModified)
dirSecurity.ModifyAccessRule(AccessControlModification.Add, usersFileSystemAccessRule, isModified)
'设置访问权限
dir.SetAccessControl(dirSecurity)
End Sub
为文件添加users,everyone用户组的完全控制权限
欢迎关注微信公众账号ByCAD