Dim ThePath = "c:\scripts"
Dim ntAcc As New NTAccount(AccountName)
'Create the access rule
Dim dsar As New FileSystemAccessRule(ntAcc, _
FileSystemRights.FullControl,
InheritanceFlags.ContainerInherit, _
PropagationFlags.None, AccessControlType.Allow)
'Create directory security object
Dim dsec As New DirectorySecurity
dsec.AddAccessRule(dsar)
'Set access
Directory.SetAccessControl(ThePath, dsec)
Dim DirectoryName as String = "\\hshshared\shared\Admin Archives"
AddDirectorySecurity(DirectoryName, "hsh\jblown",
FileSystemRights.Modify, _ AccessControlType.Allow)
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)
' 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
AddDirectorySecurity(DirectoryName, "hsh\jblown",
FileSystemRights.Modify, InheritanceFlags.ContainerInherit,
PropagationFlags.None, AccessControlType.Allow)
AddDirectorySecurity(DirectoryName, "hsh\jblown",
FileSystemRights.Modify, InheritanceFlags.ObjectInherit,
PropagationFlags.None, AccessControlType.Allow)