我有C#WinForm应用程序,需要将共享权限设置为某些文件夹,并指定哪些用户有权访问读/写/删除。我想知道是否有任何api或方法可以调用类似于右键单击文件夹的“属性/共享/高级共享”并打开窗口。
如果您知道无论如何从c#调用此窗口,如果您分享您的知识,将不胜感激。我想叫这个窗口。
您可以通过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”,“测试共享”,“这是一个测试共享”);
资料来源:http : //www.codeproject.com/Articles/18624/How-to-Share-Windows-Folders-Using-C
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句