Als erhöhter Administrator auf Vista SP1 versucht meine C#-Anwendung, die folgende Regel mit dem folgenden Code festzulegen. Es tritt kein Fehler auf, aber es gibt auch keine Änderung in der ACL des Verzeichnisses. Was übersehe ich?
public static void Main( string args[] )
{
string dirPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Company"), "Product" );
Directory.Create(dirPath);
_SetAcl(dirPath, "Users", FileSystemRights.FullControl);
}
private static void _SetAcl(string path, string identity, FileSystemRights rights)
{
var info = new DirectoryInfo(path);
var acl = info.GetAccessControl();
var rule1 = new FileSystemAccessRule(identity, rights, AccessControlType.Allow);
bool modified;
acl.ModifyAccessRule(AccessControlModification.Reset, rule1, out modified);
var inheritanceFlags = InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit;
var rule2 = new FileSystemAccessRule(identity, rights, inheritanceFlags,
PropagationFlags.InheritOnly, AccessControlType.Allow);
acl.ModifyAccessRule(AccessControlModification.Add, rule2, out modified);
}
Aktualisierung: Fügen Sie einfach den folgenden Code als letzte Zeile der _SetAcl-Methode hinzu, und mein Code ist einsatzbereit.
info.SetAccessControl(acl);