使用 C# 创建可从域访问的共享文件夹

发布于 2024-08-12 07:34:15 字数 144 浏览 5 评论 0原文

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

谢谢你, 瓦莱留

I'm doing a Deployment Project in VS2008, and at the end of the installation flow I need to create a shared folder with Full Control permissions to Everyone on the local machine accessible from a company domain.
I succeeded to create the shared folder, but Everyone has read access.
Any help on how to do this would be appreciated.

Thank you,
Valeriu

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盛夏尉蓝 2024-08-19 07:34:15

我假设您正在使用 ManagementClass创建共享文件夹

设置 ManagementBaseObject 的 Access 字段应该为每个人提供完全控制:

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);
    } 

如果上述方法都没有帮助,那么我建议你发布你的代码。

I assume you're using the ManagementClass to create a shared folder.

Setting the Access field of your ManagementBaseObject should give full control to everyone:

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

If the above doesn't work you might wanna try explicitly setting the security level with smt like the following:

    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);
    } 

If none of the above helps, then I'd suggest you post your code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文