【问题标题】:WMI Namespace "Not Found"WMI 命名空间“未找到”
【发布时间】:2012-03-31 01:24:53
【问题描述】:

我正在尝试远程运行 bat 文件(从 XP 到 2003),但在连接到除 cimv2 之外的任何 WMI 命名空间时遇到问题。下面的代码在“GetMethodParameters”调用中遇到“未找到”异常。但是如果我用“cimv2”替换“目录”,一切都是肉汁。

ConnectionOptions theConnection = new ConnectionOptions();
theConnection.Username = conDet.User;
theConnection.Password = conDet.Pwd;
theConnection.Impersonation = ImpersonationLevel.Impersonate;

ManagementScope theScope = new ManagementScope(String.Format(@"\\{0}\root\directory", conDet.Server), theConnection);
theScope.Connect();

ManagementClass processClass = new ManagementClass(theScope, new ManagementPath("Win32_Process"), new ObjectGetOptions());

enter code here
ManagementBaseObject inParams = processClass.GetMethodParameters("Create");
inParams["CommandLine"] = filename;

ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null);

我已经检查了我的机器和服务器上的安全性,两个命名空间具有相同的安全性设置。有什么想法吗?

谢谢。

【问题讨论】:

    标签: c# .net wmi


    【解决方案1】:

    您使用了错误的命名空间,Win32_Process WMI 类在 root\cimv2 中定义。

    所以你必须将你的代码重写为

    ManagementScope theScope = new ManagementScope(String.Format(@"\\{0}\root\cimv2", conDet.Server), theConnection);
    

    【讨论】:

    • 所以您是说我可以连接的唯一命名空间是 cimv2?其余的都是禁区?
    • 不,我不是说,每次建立 WMI 连接时,都必须指定特定的命名空间(范围)。因此,您可以连接到任何现有命名空间,但使用不同的 WMI 连接。
    猜你喜欢
    • 2015-02-16
    • 2019-11-20
    • 1970-01-01
    • 1970-01-01
    • 2019-03-03
    • 1970-01-01
    相关资源
    最近更新 更多