2
Vista SP1에서 상승 된 관리자로 실행 중일 때 C# app은 다음 코드로 다음 규칙을 설정하려고합니다. 오류가 생성되지는 않지만 디렉토리의 ACL이 변경되지는 않습니다. 내가 뭘 놓치고 있니?C#에서이 ACL 규칙을 설정할 수없는 이유는 무엇입니까?
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);
}
업데이트 :는 그냥 _SetAcl 방법의 마지막 줄에 다음 코드를 추가하고, 내 코드가 갈 수 있습니다.
info.SetAccessControl(acl);
D' oh! 그랬어. 감사. – flipdoubt