jjzjj

c# - 无法检查新目录上的 'Include inheritable permissions'

coder 2024-06-21 原文

我正在尝试创建新目录并以编程方式设置权限。我已经能够创建目录,为单个用户和组应用权限,并更新大多数继承和传播设置。但是,我无法使用代码检查 Window GUI 界面中的 Include inheritable permissions from this object's parent 选项(见下文)。

我试过使用 Inheritance 和 Propogation 标志的替代值,以及 SetAccessRuleProtection 参数,但我似乎找不到任何有效的排列。

代码示例:

using System.Security.AccessControl;

//...

string dir = @"C:\MyTestFolder";

DirectorySecurity dirSec = new DirectorySecurity();

dirSec.AddAccessRule(
    new FileSystemAccessRule(@"contoso.com\myuser",
        FileSystemRights.FullControl,
        InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
        PropagationFlags.None,
        AccessControlType.Allow));

dirSec.SetAccessRuleProtection(false, true);

Directory.CreateDirectory(dir, dirSec);

不确定它是否相关,但我正在使用它为用户创建主目录,因此计划是让用户具有修改权限并继承或添加具有完全权限的 SYSTEM 和 Administrators 本地用户/组。

我试过了 many other examples从 StackOverflow 上的这里开始,但似乎没有任何东西可以检查那个讨厌的框。有什么想法吗?

编辑:这里是我所指的复选框。请注意,这些不是我的特定屏幕截图,而只是演示。

此图像显示第二个窗口中的灰色复选框,以及第三个窗口中的可访问复选框。就我而言,当我使用上述代码创建文件夹时(并使用 SetAccessRuleProtection 或 Inheritance 和 Propagation 标志的参数的任何变体),两个框都未选中。

我的意图是在创建目录时选中这些 GUI 复选框(并因此在后台设置它们的适当权限),以便它看起来与图像类似。

最佳答案

看起来这一切都归结为操作顺序。似乎如果我通过提供 DirectorySecurity 创建目录,它将创建文件夹,文件夹权限被我提供的内容完全覆盖。而且,出于某种原因,如果我调用 SetAccessRuleProtection 来为我在创建过程中 提供的 DirectorySecurity 设置文件夹的可继承权限,它不会发生。

但是,如果我先创建文件夹而不提供任何权限信息,则创建时默认选中该框,然后我可以根据需要添加我的 AccessRule:

using System.Security.AccessControl;

//...

string dir = @"C:\MyTestFolder";

//If you update and add the access rules here, it doesn't work

Directory.CreateDirectory(dir);

//Now that the folder has been created...
DirectorySecurity dirSec = Directory.GetAccessControl(dir);
dirSec.AddAccessRule(
    new FileSystemAccessRule(@"contoso.com\myuser",
        FileSystemRights.FullControl,
        InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
        PropagationFlags.None,
        AccessControlType.Allow));
//this isn't really necessary at this point, but wouldn't hurt:
//dirSec.SetAccessRuleProtection(false, true);
Directory.SetAccessControl(dir, dirSec);

我不知道为什么必须按此特定顺序执行此操作的原因,但如果有人有洞察力,我很想听听原因。无论如何,这让我现在可以毫无问题地工作。

关于c# - 无法检查新目录上的 'Include inheritable permissions',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28174414/

有关c# - 无法检查新目录上的 'Include inheritable permissions'的更多相关文章

  1. ruby-on-rails - rails : "missing partial" when calling 'render' in RSpec test - 2

    我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou

  2. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  3. ruby-on-rails - 'compass watch' 是如何工作的/它是如何与 rails 一起使用的 - 2

    我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t

  4. ruby-on-rails - 无法使用 Rails 3.2 创建插件? - 2

    我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby​​1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在

  5. ruby-on-rails - Rails 3.2.1 中 ActionMailer 中的未定义方法 'default_content_type=' - 2

    我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer

  6. ruby - 无法运行 Rails 2.x 应用程序 - 2

    我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby​​:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r

  7. ruby - 在 jRuby 中使用 'fork' 生成进程的替代方案? - 2

    在MRIRuby中我可以这样做:deftransferinternal_server=self.init_serverpid=forkdointernal_server.runend#Maketheserverprocessrunindependently.Process.detach(pid)internal_client=self.init_client#Dootherstuffwithconnectingtointernal_server...internal_client.post('somedata')ensure#KillserverProcess.kill('KILL',

  8. ruby-on-rails - 无法在centos上安装therubyracer(V8和GCC出错) - 2

    我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e

  9. ruby - 主要 :Object when running build from sublime 的未定义方法 `require_relative' - 2

    我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby​​1.9+ 关于ruby-主要:Objectwhenrun

  10. ruby - 无法让 RSpec 工作—— 'require' : cannot load such file - 2

    我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳

随机推荐