Kib*_*ria 13 .net c# windows winapi
我必须使用C#.NET以编程方式为文件夹及其子文件夹和文件分配权限.我这样做如下:
var rootDic = @"C:\ROOT";
var identity = "NETWORK SERVICE"; //The name of a user account.
try
{
var accessRule = new FileSystemAccessRule(identity,
fileSystemRights: FileSystemRights.Modify,
inheritanceFlags: InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
propagationFlags: PropagationFlags.InheritOnly,
type: AccessControlType.Allow);
var directoryInfo = new DirectoryInfo(rootDic);
// Get a DirectorySecurity object that represents the current security settings.
DirectorySecurity dSecurity = directoryInfo.GetAccessControl();
// Add the FileSystemAccessRule to the security settings.
dSecurity.AddAccessRule(accessRule);
// Set the new access settings.
directoryInfo.SetAccessControl(dSecurity);
}
catch (Exception ex)
{
//...
}
Run Code Online (Sandbox Code Playgroud)
它确实为我的'C:\ ROOT'文件夹分配权限.但它仅为子文件夹和文件分配权限,但不为"ROOT"文件夹分配权限.
问:如何定义FileSystemAccessRule
实例以为ROOT文件夹,子文件夹和文件分配权限?
归档时间: |
|
查看次数: |
9848 次 |
最近记录: |