Ordnerberechtigung vergeben/entziehen

  • VB.NET

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von Wolfi.

    Ordnerberechtigung vergeben/entziehen

    Hallo

    Mit dem folgenden Code (teilweise übernommen aus MSDN) kann ich bestimmten Usern oder Gruppen Zugriffsrechte erteilen und wieder entziehen:

    VB.NET-Quellcode

    1. Sub AddDirectorySecurity(ByVal FileName As String, ByVal Account As String, ByVal Rights As FileSystemRights, ByVal ControlType As AccessControlType)
    2. ' Create a new DirectoryInfoobject.
    3. Dim dInfo As New DirectoryInfo(FileName)
    4. ' Get a DirectorySecurity object that represents the
    5. ' current security settings.
    6. Dim dSecurity As DirectorySecurity = dInfo.GetAccessControl()
    7. ' Add the FileSystemAccessRule to the security settings.
    8. dSecurity.AddAccessRule(New FileSystemAccessRule(Account, Rights, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit, PropagationFlags.None, ControlType))
    9. ' Set the new access settings.
    10. dInfo.SetAccessControl(dSecurity)
    11. End Sub
    12. ' Removes an ACL entry on the specified directory for the specified account.
    13. Sub RemoveDirectorySecurity(ByVal FileName As String, ByVal Account As String, ByVal Rights As FileSystemRights, ByVal ControlType As AccessControlType)
    14. ' Create a new DirectoryInfo object.
    15. Dim dInfo As New DirectoryInfo(FileName)
    16. ' Get a DirectorySecurity object that represents the
    17. ' current security settings.
    18. Dim dSecurity As DirectorySecurity = dInfo.GetAccessControl()
    19. ' Add the FileSystemAccessRule to the security settings.
    20. dSecurity.RemoveAccessRule(New FileSystemAccessRule(Account, Rights, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit, PropagationFlags.None, ControlType))
    21. ' Set the new access settings.
    22. dInfo.SetAccessControl(dSecurity)
    23. 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!
    Ich habe es jetzt anders gelöst. Mit dem folgenden Powershell-Script klappt das Löschen aus der ACL wunderbar:

    $Verzeichnis = "Pfad"
    $aclVZ = get-acl $Verzeichnis
    $arVZ = new-object system.security.accesscontrol.filesystemaccessrule("Intranet\grp_sec_praktikanten","Modify", "ContainerInherit, ObjectInherit", "None", "Allow")
    $aclVZ.RemoveAccessRule($arVZ)
    set-acl $Verzeichnis $aclVZ

    Danke!