1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
Sub Acl_folder(ByVal Tfolder, ByVal Tuser)
Try
' Add the access control entry to the file.
AddDirectorySecurity(Tfolder, Tuser, _
FileSystemRights.Write, AccessControlType.Allow)
Catch e As Exception
Console.WriteLine(e)
End Try
End Sub
Sub AddDirectorySecurity(ByVal FileName As String, ByVal Account As String, ByVal Rights As FileSystemRights, ByVal ControlType As AccessControlType)
' Create a new DirectoryInfoobject.
Dim dInfo As New DirectoryInfo(FileName)
'Dim heritage As InheritanceFlags
'Dim propagationheritage As PropagationFlags
' Get a DirectorySecurity object that represents the
' current security settings.
Dim dSecurity As DirectorySecurity = dInfo.GetAccessControl()
' Add the FileSystemAccessRule to the security settings.
dSecurity.AddAccessRule(New FileSystemAccessRule(Account, Rights, ControlType))
' Set the new access settings.
dInfo.SetAccessControl(dSecurity)
End Sub |
Partager