C# 如何在Windows 7上共享文件夹
我正在使用C#创建文件夹并在网络上共享:C# 如何在Windows 7上共享文件夹,c#,networking,directory,C#,Networking,Directory,我正在使用C#创建文件夹并在网络上共享: 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
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");
}
}
它在XP上工作,但我无法在Windows7上共享此代码中的文件夹
有人能告诉我如何使用C#在Windows 7中共享文件夹吗?您的应用程序需要以管理权限运行才能共享文件夹 如果你看一下下面的链接,它讨论的是与你正在处理的情况相同的情况。大约在一半的时候,有一个公认的答案,它将介绍它在Windows7机器上工作所需的其他操作 链接: 希望这有助于取代
\
在你的道路上
/
您得到了什么错误/异常?如果UAC出现问题,您是否尝试过以管理员身份运行代码?此代码中没有错误。我得到了outParams.Properties[“ReturnValue”].Value=2,之后我检查了文件夹,发现该文件夹上没有共享。请尝试以管理员身份运行应用程序。