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);