[英]Sharing Folder API
I have C# WinForm application that needs to set sharing permission to some folder, and specify what users have access read/write/delete. 我有C#WinForm应用程序,需要为某个文件夹设置共享权限,并指定用户具有读/写/删除权限。 I was wondering if there is any api or way to call something similar to when you right click on folder select Properties/Sharing/Advanced Sharing and window opens.
我想知道是否有任何api或方式来调用类似于右键单击文件夹时选择属性/共享/高级共享并打开窗口。
If you know of anyway calling this window from c# I would appreciate if you share your knowledge. 如果您知道无论如何从c#调用此窗口,我将不胜感激,如果您分享您的知识。 I want to call this window.
我想打电话给这个窗口。
There is no any standart API for this task. 此任务没有任何标准API。
Try this project to implement what you need How to Share Windows Folders Using C# (and here there is another example 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 ) 试试这个项目来实现你需要的东西如何使用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-programmingically-in-windows-7-or?forum = windowssdk )
Notice that your application will need to be running with Administrative access in order to share a folder. 请注意,您的应用程序需要以管理员权限运行才能共享文件夹。
You can do it through Win32 API: 你可以通过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!");
}
}
Usage: QshareFolder("c:\\TestShare", "Test Share", "This is a Test Share"); 用法:QshareFolder(“c:\\ TestShare”,“Test Share”,“This is a Test Share”);
Source: http://www.codeproject.com/Articles/18624/How-to-Share-Windows-Folders-Using-C 资料来源: http : //www.codeproject.com/Articles/18624/How-to-Share-Windows-Folders-Using-C
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.