c# – 以编程方式创建共享失败,错误9

c# – 以编程方式创建共享失败,错误9,第1张

概述ObjectGetOptions options = new ObjectGetOptions(); ManagementPath p = new ManagementPath("\\\\server01\\root" + "\\cimv2:Win32_Share");// Make a connection to a remote computer.ManagementScope sco
ObjectGetoptions options = new ObjectGetoptions(); ManagementPath p = new ManagementPath("\\server01\root" + "\cimv2:Win32_Share");// Make a connection to a remote computer.ManagementScope scope = new ManagementScope("\\server01\root\cimv2");scope.Connect();// Create a ManagementClass objectManagementClass managementClass = new ManagementClass(scope,p,options);// Create ManagementBaSEObjects for in and out parametersManagementBaSEObject inParams = managementClass.getmethodParameters("Create");ManagementBaSEObject outParams;// Set the input parameters//inParams["Description"] = String.Empty;inParams["name"] = "test";inParams["Path"] = @folderPath;inParams["Type"] = 0x0; // disk Drive// Invoke the method on the ManagementClass objectoutParams = managementClass.InvokeMethod("Create",inParams,null);// Check to see if the method invocation was successfulif ((uint)(outParams.PropertIEs["ReturnValue"].Value) != 0){      throw new Exception("Unable to share directory.  Error code: " + outParams.PropertIEs["ReturnValue"].Value);}}catch (Exception e){    MessageBox.Show(e.Message.ToString());}}

我使用以下代码来设置共享,但我总是得到返回值9,这意味着名称无效.我传递一个字符串,并尝试使用显式字符串,我仍然得到错误9.

我是远程创建共享而不是在本地计算机上创建共享.我试图确保我连接到远程WMI提供程序,但我不确定我是否成功.

WMI大师和其他人的任何建议都非常感谢.

解决方法 在另一个网站上找到答案.文件夹路径需要是创建共享的机器的本地路径,而不是像我正在使用的UNC路径. 总结

以上是内存溢出为你收集整理的c# – 以编程方式创建共享失败,错误9全部内容,希望文章能够帮你解决c# – 以编程方式创建共享失败,错误9所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/langs/1242379.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存