Private Sub AddFileSecurity(ByVal fileName As String, ByVal account As String, _ ByVal rights As FileSystemRights, ByVal controlType As AccessControlType)
' Get a FileSecurity object that represents the
' current security settings.
Try
Dim fSecurity As FileSecurity = File.GetAccessControl(fileName)
fSecurity.AddAccessRule(New FileSystemAccessRule(account, rights, controlType))
fSecurity.AddAccessRule( New FileSystemAccessRule(account, rights, _ InheritanceFlags.ObjectInherit Or InheritanceFlags.ContainerInherit, _ PropagationFlags.InheritOnly, AccessControlType.Allow))
Dim currentUser As Security.Principal.NTAccount = _ New Security.Principal.NTAccount(_ShortDomainName, _Username)
fSecurity.SetOwner(currentUser)
' Set the new access settings.
File.SetAccessControl(fileName, fSecurity)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
|