Frage siehe Titel
Es reicht nicht nur die Rechte einer gruppe oder eines benutzers zu entfernen!
hat jemand ne idee?
greets
mex
que? como? no entiendo!!!!!
Ich meine das müsste mit diesen Methoden klappen:
// Removes an ACL entry on the specified directory for the specified account.
public void RemoveDirectorySecurity(string FileName, string Account, FileSystemRights Rights,
InheritanceFlags Inheritance, PropagationFlags Propogation,
AccessControlType ControlType)
{
// Create a new DirectoryInfo object.
DirectoryInfo dInfo = new DirectoryInfo(FileName);
// Get a DirectorySecurity object that represents the
// current security settings.
DirectorySecurity dSecurity = dInfo.GetAccessControl();
// Add the FileSystemAccessRule to the security settings.
dSecurity.RemoveAccessRule(new FileSystemAccessRule(Account,
Rights,
Inheritance,
Propogation,
ControlType));
// Set the new access settings.
dInfo.SetAccessControl(dSecurity);
}
// Removes an ACL entry on the specified directory for the specified account.
public void RemoveInheritablePermissons(string FileName)
{
// Create a new DirectoryInfo object.
DirectoryInfo dInfo = new DirectoryInfo(FileName);
// Get a DirectorySecurity object that represents the
// current security settings.
DirectorySecurity dSecurity = dInfo.GetAccessControl();
// Add the FileSystemAccessRule to the security settings.
const bool IsProtected = true;
const bool PreserveInheritance = false;
dSecurity.SetAccessRuleProtection(IsProtected, PreserveInheritance);
// Set the new access settings.
dInfo.SetAccessControl(dSecurity);
}
public void RemoveDirectorySecurityRecursive(string FileName, string Account, FileSystemRights Rights,
InheritanceFlags Inheritance, PropagationFlags Propogation,
AccessControlType ControlType)
{
try
{
string[] subDirs = Directory.GetDirectories(FileName);
// Im aktuellen Ordner die Rechte setzen
RemoveDirectorySecurity(FileName, Account, Rights, Inheritance, Propogation, ControlType);
foreach (String strSubDir in subDirs)
{
// Rekursiver Abstieg
RemoveDirectorySecurityRecursive(strSubDir, Account, Rights, Inheritance, Propogation, ControlType);
// Im Unterordner die Rechte setzen
RemoveDirectorySecurity(strSubDir, Account, Rights, Inheritance, Propogation, ControlType);
}
}
catch
{
}
}
Ein Aufruf der Methode zum Lese. und Schreibrechte entfernen könnte dann so aussehen:
accessManager.RemoveDirectorySecurityRecursive(args[4], "AF-HH\\" + args[3], FileSystemRights.FullControl,
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
PropagationFlags.None, AccessControlType.Allow);
ohne den Code explizit getestet zu haben - das sieht gut aus 😉
Danke für die schnelle Hilfe
beim debuggen sollte man sich aber nicht wunder wenn nach ausführen des Codeblocks nicht alle Gruppen oder Benutzer in den Properties entfernt sind - den grund dieses Verhaltens kann ich allerdings nicht nachvollziehen
Vermutung - Vererbung bzw. Konfiguration von den übergeordneten Ordnern die Windows übernimmt
greets
mex
que? como? no entiendo!!!!!