|
Private Sub AddFileSecurity(ByVal fileName As String, ByVal account As String, _ ' 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 ExceptionMsgBox(ex.ToString) End Try End Sub |
I'm catching "System.ArgumentException: No flags can be set" at the File.SetAccessControl line. I've already set up all my stops and checked my variables and they're in the correct format (so I think anyways). Any help would be appreciated.
Jan MontanoPosted Jul 2, 2007, 11:45 PM
I think your problem has something to do with this line:
fSecurity.AddAccessRule(New FileSystemAccessRule(account, rights, _
InheritanceFlags.ObjectInherit Or InheritanceFlags.ContainerInherit, _
PropagationFlags.InheritOnly, AccessControlType.Allow))
I'm not sure if you really need to set ObjectInherit or ContainerInherit for the InheritanceFlags, but using InhertanceFlags.None solved the problem for me.