Hallo
Mit dem folgenden Code (teilweise übernommen aus MSDN) kann ich bestimmten Usern oder Gruppen Zugriffsrechte erteilen und wieder entziehen:
Das ganze funktioniert eigentlich wunderbar. Etwas unschön ist aber, dass die Funktion "RemoveDirectorySecurity" dem gewählten Benutzer zwar alle Rechte entzieht, der Benutzer (ohne Rechte) aber in der ACL stehen bleibt. Wie kann ich den Benutzer oder die Gruppe ganz aus der ACL entfernen?
Ich freue mich auf eine Rückmeldung! Vielen Dank!
Mit dem folgenden Code (teilweise übernommen aus MSDN) kann ich bestimmten Usern oder Gruppen Zugriffsrechte erteilen und wieder entziehen:
VB.NET-Quellcode
- 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, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit, PropagationFlags.None, ControlType))
- ' Set the new access settings.
- dInfo.SetAccessControl(dSecurity)
- End Sub
- ' Removes an ACL entry on the specified directory for the specified account.
- Sub RemoveDirectorySecurity(ByVal FileName As String, ByVal Account As String, ByVal Rights As FileSystemRights, ByVal ControlType As AccessControlType)
- ' Create a new DirectoryInfo object.
- 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.RemoveAccessRule(New FileSystemAccessRule(Account, Rights, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit, PropagationFlags.None, ControlType))
- ' Set the new access settings.
- dInfo.SetAccessControl(dSecurity)
- End Sub
Das ganze funktioniert eigentlich wunderbar. Etwas unschön ist aber, dass die Funktion "RemoveDirectorySecurity" dem gewählten Benutzer zwar alle Rechte entzieht, der Benutzer (ohne Rechte) aber in der ACL stehen bleibt. Wie kann ich den Benutzer oder die Gruppe ganz aus der ACL entfernen?
Ich freue mich auf eine Rückmeldung! Vielen Dank!