共享文件夹 API
Sharing Folder API
我有一个 C# WinForm 应用程序,它需要为某些文件夹设置共享权限,并指定哪些用户可以访问 read/write/delete。
我想知道是否有任何 api 或调用类似于当您右键单击文件夹 select Properties/Sharing/Advanced 共享并打开 window 时调用的方法。
如果您知道无论如何从 c# 调用此 window,如果您分享您的知识,我将不胜感激。
我想把这个叫做 window.
此任务没有任何标准API。
试试这个项目来实现你需要的东西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)
请注意,您的应用程序需要 运行 管理权限才能共享文件夹。
您可以通过 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", "Test Share", "This is a Test Share");
来源:http://www.codeproject.com/Articles/18624/How-to-Share-Windows-Folders-Using-C
我有一个 C# WinForm 应用程序,它需要为某些文件夹设置共享权限,并指定哪些用户可以访问 read/write/delete。 我想知道是否有任何 api 或调用类似于当您右键单击文件夹 select Properties/Sharing/Advanced 共享并打开 window 时调用的方法。
如果您知道无论如何从 c# 调用此 window,如果您分享您的知识,我将不胜感激。 我想把这个叫做 window.
此任务没有任何标准API。
试试这个项目来实现你需要的东西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)
请注意,您的应用程序需要 运行 管理权限才能共享文件夹。
您可以通过 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", "Test Share", "This is a Test Share");
来源:http://www.codeproject.com/Articles/18624/How-to-Share-Windows-Folders-Using-C