我的C# WinForm应用程序需要为某些文件夹设置共享权限,并指定哪些用户可以访问读/写/删除。我在想,当您右键单击文件夹、选择属性/共享/高级共享和窗口时,是否有任何api或方法来调用类似的东西。

如果您知道,无论如何,从c#调用这个窗口,我将感谢您分享您的知识。我想打电话给这扇窗户。
发布于 2015-06-02 16:18:43
您可以通过Win32 API做到这一点:
private static void QshareFolder(string FolderPath, string ShareName, string Description)
{
try
{
// Create a ManagementClass object
ManagementClass managementClass = new ManagementClass("Win32_Share");
// Create ManagementBaseObjects for in and out parameters
ManagementBaseObject inParams = managementClass.GetMethodParameters("Create");
ManagementBaseObject outParams;
// Set the input parameters
inParams["Description"] = Description;
inParams["Name"] = ShareName;
inParams["Path"] = FolderPath;
inParams["Type"] = 0x0; // Disk Drive
// Invoke the method on the ManagementClass object
outParams = managementClass.InvokeMethod("Create", inParams, null);
if ((uint)(outParams.Properties["ReturnValue"].Value) != 0)
{
throw new Exception("Unable to share directory.");
}
}
catch (Exception ex)
{
//MessageBox.Show(ex.Message, "error!");
}
}用法: QshareFolder("c:\TestShare",“TestShare”,“这是一个测试共享”);
来源:http://www.codeproject.com/Articles/18624/How-to-Share-Windows-Folders-Using-C
发布于 2015-06-02 16:15:29
对于此任务,没有任何标准API。
尝试这个项目来实现您需要的如何使用C#共享Windows文件夹 (这里还有另一个示例https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/de213b61-dc7e-4f33-acdb-893aa96837fa/c-set-directory-sharing-permission-full-control-for-everyone-programmatically-in-windows-7-or?forum=windowssdk)
请注意,为了共享文件夹,您的应用程序需要使用“管理访问”运行。
https://stackoverflow.com/questions/30601125
复制相似问题