【问题标题】:Create shared folder accessible from domain with C#使用 C# 创建可从域访问的共享文件夹
【发布时间】:2009-11-23 14:16:28
【问题描述】:

我正在 VS2008 中进行部署项目,在安装流程结束时,我需要创建一个共享文件夹,该文件夹对可从公司域访问的本地计算机上的每个人具有完全控制权限。 我成功创建了共享文件夹,但每个人都有读取权限。 任何有关如何执行此操作的帮助将不胜感激。

谢谢你, 瓦莱里乌

【问题讨论】:

    标签: c# deployment-project


    【解决方案1】:

    我假设您使用的是 ManagementClass 到 create a shared folder。

    设置ManagementBaseObject 的访问字段应该让每个人都可以完全控制:

    ManagementClass mc = new ManagementClass("win32_share");
    ManagementBaseObject inParams = mc.GetMethodParameters("Create");
    inParams["Description"] = "Shared Folder";
    // ... whathever ...
    inParams["Access"] = null; // <-- should give full control access to everyone
    

    如果上述方法不起作用,您可能想尝试使用 smt 显式设置安全级别,如下所示:

        public static void AddDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType)
        {
            DirectoryInfo dInfo = new DirectoryInfo(FileName);
    
            DirectorySecurity dSecurity = dInfo.GetAccessControl();
    
            // Add the FileSystemAccessRule to the security settings.  
            dSecurity.AddAccessRule(new FileSystemAccessRule(Account,
                                                             Rights,
                                                             ControlType));
            // Set the new access settings. 
            dInfo.SetAccessControl(dSecurity);
        } 
    

    如果以上都没有帮助,那么我建议您发布您的代码。

    【讨论】:

    • 代码没什么特别的。安装程序只是在本地机器上创建一个目录并尝试共享它。我也试过你的代码,但还是不行。 ManagementClass mc = new ManagementClass("win32_share");确实,代码在域上共享目录,但仅对所有人具有读取权限。 AddDirectorySecurity 方法什么都不做。
    • 会不会是因为安装程序是用系统用户运行的,没有足够的权限?
    • 我也认为 inParams["Access"] = null;授予所有人访问权限,但只读
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多