2 回答
TA贡献1829条经验 获得超9个赞
您需要指定继承标志:
directorySecurity.AddAccessRule(new FileSystemAccessRule(@"NT Service\FileMoverService",
FileSystemRights.FullControl,
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
PropagationFlags.None,
AccessControlType.Allow));
TA贡献1820条经验 获得超2个赞
该方法GrantFullControl可用于设置Full Control给定目录和用户的权限。
private static void GrantFullControl(string directoryPath, string username)
{
if (!Directory.Exists(directoryPath))
return;
var directorySecurity = Directory.GetAccessControl(directoryPath);
directorySecurity.AddAccessRule(new FileSystemAccessRule(username, FileSystemRights.FullControl,
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None,
AccessControlType.Allow));
Directory.SetAccessControl(directoryPath, directorySecurity);
}
只需调用如下所示的方法。
GrantFullControl(@"C:\Test", @"NT Service\FileMoverService");
- 2 回答
- 0 关注
- 196 浏览
添加回答
举报