本文整理汇总了C#中System.Security.AccessControl.DirectorySecurity.RemoveAccessRule方法的典型用法代码示例。如果您正苦于以下问题:C# DirectorySecurity.RemoveAccessRule方法的具体用法?C# DirectorySecurity.RemoveAccessRule怎么用?C# DirectorySecurity.RemoveAccessRule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.AccessControl.DirectorySecurity
的用法示例。
在下文中一共展示了DirectorySecurity.RemoveAccessRule方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteOnDir
protected override void ExecuteOnDir(DirectoryInfo dir)
{
DirectorySecurity dirSec = new DirectorySecurity(dir.FullName, AccessControlSections.Access);
IList<FileSystemAccessRule> targetRules = FindAccessRules(dirSec);
if (targetRules.Count == 0)
{
Log(Level.Info, Resources.RemoveAccessRuleEmpty, NTAccount, dir.FullName);
}
else
{
foreach (FileSystemAccessRule fileSystemAccessRule in targetRules)
{
Log(Level.Info, Resources.RemoveAccessRuleRemoving, NTAccount, dir.FullName);
dirSec.RemoveAccessRule(fileSystemAccessRule);
}
dir.SetAccessControl(dirSec);
}
}
示例2: RemoveAllExplicitAccessRules
/// <summary>
/// Removes all explicit access rules from the supplied directory.
/// </summary>
/// <param name="path">The path to the directory to have access removed on.</param>
/// <param name="security">The DirectorySecurity object of the directory that will be changed.</param>
/// <param name="commitChanges">Indicates whether changes should be commited to this directory. Useful when combining multiple commands.</param>
/// <returns>True if access was removed. False otherwise.</returns>
public static bool RemoveAllExplicitAccessRules(string path, ref DirectorySecurity security, bool commitChanges)
{
// Check whether the path and security object are supplied.
if (!string.IsNullOrEmpty(path) && security != null)
{
// Check whether the directory exists.
if (SystemDirectory.Exists(path))
{
// A path and security object are supplied.
// Remove existing explicit permissions.
security = GetSecurityObject(path);
AuthorizationRuleCollection rules = security.GetAccessRules(true, false, typeof(SecurityIdentifier));
foreach (AuthorizationRule rule in rules)
{
security.RemoveAccessRule((FileSystemAccessRule)rule);
}
// Commit the changes if necessary.
if (commitChanges)
{
try
{
SystemDirectory.SetAccessControl(path, security);
}
catch (UnauthorizedAccessException)
{
// The current process does not have access to the directory specified by path.
// Or the current process does not have sufficient privilege to set the ACL entry.
return false;
}
catch (PlatformNotSupportedException)
{
// The current operating system is not Windows 2000 or later.
return false;
}
}
return true;
}
else
{
// The directory does not exist.
return false;
}
}
else
{
// A path and security object were not supplied.
return false;
}
}