3 回答

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超5個(gè)贊
我想告訴你的第一件事是我如何找到這個(gè)解決方案的。這可能比答案更重要,因?yàn)槲募?quán)限很難正確獲得。
我要做的第一件事是使用Windows對(duì)話框和復(fù)選框設(shè)置所需的權(quán)限。我為“所有人”添加了一條規(guī)則,并勾選了“完全控制”之外的所有框。
然后,我編寫(xiě)了此C#代碼,以確切地告訴我復(fù)制Windows設(shè)置所需的參數(shù):
string path = @"C:\Users\you\Desktop\perms"; // path to directory whose settings you have already correctly configured
DirectorySecurity sec = Directory.GetAccessControl(path);
foreach (FileSystemAccessRule acr in sec.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount))) {
Console.WriteLine("{0} | {1} | {2} | {3} | {4}", acr.IdentityReference.Value, acr.FileSystemRights, acr.InheritanceFlags, acr.PropagationFlags, acr.AccessControlType);
}
這給了我這行輸出:
Everyone | Modify, Synchronize | ContainerInherit, ObjectInherit | None | Allow
因此,解決方案很簡(jiǎn)單(但如果您不知道要尋找什么,就很難正確解決?。?/p>
DirectorySecurity sec = Directory.GetAccessControl(path);
// Using this instead of the "Everyone" string means we work on non-English systems.
SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
sec.AddAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.Modify | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
Directory.SetAccessControl(path, sec);
這將使Windows安全對(duì)話框中的復(fù)選框與您已為測(cè)試目錄設(shè)置的復(fù)選框匹配。

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超6個(gè)贊
使用FileSystemRights.FullControl
替代FileSystemRights.Modify
,如果你想允許所有操作(ACL)。
- 3 回答
- 0 關(guān)注
- 272 瀏覽
添加回答
舉報(bào)