加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 18:33:38 所属栏目:百科 来源:网络整理
导读:ObjectGetOptions options = new ObjectGetOptions(); ManagementPath p = new ManagementPath("\server01root" + "cimv2:Win32_Share");// Make a connection to a remote computer.ManagementScope scope = new ManagementScope("\server01roo
ObjectGetOptions options = new ObjectGetOptions();
 ManagementPath p = new ManagementPath("\server01root" + "cimv2:Win32_Share");

// Make a connection to a remote computer.
ManagementScope scope = new ManagementScope("\server01rootcimv2");
scope.Connect();


// Create a ManagementClass object
ManagementClass managementClass = new ManagementClass(scope,p,options);
// Create ManagementBaSEObjects for in and out parameters
ManagementBaSEObject 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 object
outParams = managementClass.InvokeMethod("Create",inParams,null);
// Check to see if the method invocation was successful
if ((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路径.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读