En cours d'exécution en tant qu'administrateur élevé sur Vista SP1, mon application C# essaie de définir la règle suivante avec le code suivant. Aucune erreur n'est produite, mais aucune modification n'est apportée à la liste de contrôle d'accès du répertoire. Qu'est-ce que je rate?Pourquoi ne puis-je pas définir cette règle ACL en C#?
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);
}
Mise à jour: Il suffit d'ajouter le code suivant la dernière ligne de la méthode _SetAcl et mon code est bon d'aller.
info.SetAccessControl(acl);
D'oh! C'est ce qu'il a fait. Merci. – flipdoubt