0

I am using C# to create a folder and share it on the network:

if (!System.IO.Directory.Exists(FolderPath))
{
      System.IO.Directory.CreateDirectory(FolderPath);
      // Calling Win32_Share class to create a shared folder
      ManagementClass managementClass = new ManagementClass("Win32_Share");
      // Get the parameter for the Create Method for the folder
      ManagementBaseObject inParams = managementClass.GetMethodParameters("Create");
      ManagementBaseObject outParams;
      // Assigning the values to the parameters
      inParams["Description"] = Description;
      inParams["Name"] = ShareName;
      inParams["Path"] = FolderPath;
      inParams["Type"] = 0x0;
      // Finally Invoke the Create Method to do the process
      outParams = managementClass.InvokeMethod("Create", inParams, null);
      // Validation done here to check sharing is done or not
      if ((uint)(outParams.Properties["ReturnValue"].Value) != 0)
      {
           //MessageBox.Show("Folder might be already in share or unable to share the directory");
      }
}

It works on XP, but I am not able to share a folder from this code on Windows 7.

Can anyone tell me how I can share a folder in Windows 7 using C#?

4

2 回答 2

0

您的应用程序需要以管理权限运行才能共享文件夹。

如果您查看以下链接,它会讨论与您正在处理的情况似乎相同的情况。大约一半有一个公认的答案,其中介绍了它在 Windows 7 机器上工作所需的额外操作。

链接:http ://social.msdn.microsoft.com/Forums/en-US/windowssdk/thread/de213b61-dc7e-4f33-acdb-893aa96837fa

希望这可以帮助

于 2013-04-15T11:17:39.687 回答
0

更换

\ 

在你的路上

/
于 2018-09-25T17:41:12.820 回答