微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何查看是否对文件或文件夹select“包含可inheritance的权限”?

我在C#编写一个小实用程序,以确保指定的文件夹及其所有内容具有适当的访问权限(我想授予Authenticated Users组完全访问权限)。 下面的代码似乎正常工作更新顶级文件夹的ACL(访问控制列表):

SecurityIdentifier allUsers = new SecurityIdentifier(WellKNownSidType.AuthenticatedUserSid,null); InheritanceFlags iFlags = InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit; FileSystemAccessRule newRule = new FileSystemAccessRule(allUsers,FileSystemRights.FullControl,iFlags,PropagationFlags.None,AccessControlType.Allow); DirectoryInfo info = new DirectoryInfo(folderPath); DirectorySecurity security = info.GetAccessControl(); security.AddAccessRule(newRule); info.SetAccessControl(security);

但是,我注意到,这个新的访问规则不会传播到在其安全属性中未选中“包含可inheritance权限…”选项的子文件夹。 这只是有道理的。 所以,我想要做的是打开任何这样的子文件夹的安全权限inheritance。

我的挖掘发现了ObjectSecurity.SetAccessRuleProtection方法应该是我需要的一半。 但是,在已经inheritance父类的DACL的对象上盲目地使用上述方法似乎是草率的。 因此,我想确定哪些对象的权限inheritanceclosures,但我似乎无法find相应的方法或返回此信息的属性。 有一个吗? 我在这里错过了什么?

如何从PowerShell 1.0调用DLL方法

Win C#:以pipe理员身份运行应用程序,无需UAC提示

应用程序不工作没有pipe理权限

Windows服务来检测networking更改事件

更改Windows 7窗口颜色

multidatatrigger的Enteraction中的ColorAnimation在项目添加到ListView时不会触发

processstartinfo.UseShellExecute有什么大不了的?

如何使用与Explorer相同的选项创build上下文菜单

在.NET中编写虚拟打印机

创build原始graphics元素(没有Windows铬)

我记得使用这样的东西:

DirectoryInfo d = new DirectoryInfo(@"e:test1"); DirectorySecurity acl = d.GetAccessControl(); if (acl.GetAccessRules(false,true,typeof(System.Security.Principal.SecurityIdentifier)).Count >0) // -- has inherited permissions else // -- has no inherited permissions

我也试图找到一个方法来检查,但我找不到任何(即使在C + +)。 所以我最终使用了上面的代码。 它像一个魅力工作。

似乎有一个管理的方式来做到这一点:

DirectorySecurity ds = System.IO.Directory.GetAccessControl(@"C:test"); byte[] rawBytes = ds.GetSecurityDescriptorBinaryForm(); RawSecurityDescriptor rsd = new RawSecurityDescriptor(rawBytes,0); if ((rsd.ControlFlags & ControlFlags.discretionaryAclProtected) == ControlFlags.discretionaryAclProtected) { // "Include inheritable permissions from this object's parent" is unchecked } else { // "Include inheritable permissons from this object's parent" is checked }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐