C# WMI名称空间";“未找到”;
我试图远程运行一个bat文件(从XP到2003),但在连接到除cimv2以外的任何WMI命名空间时遇到问题。下面的代码在“GetMethodParameters”调用中遇到了“Not Found”异常。但是,如果我用“cimv2”替换“目录”,一切都很重要C# WMI名称空间";“未找到”;,c#,.net,wmi,C#,.net,Wmi,我试图远程运行一个bat文件(从XP到2003),但在连接到除cimv2以外的任何WMI命名空间时遇到问题。下面的代码在“GetMethodParameters”调用中遇到了“Not Found”异常。但是,如果我用“cimv2”替换“目录”,一切都很重要 ConnectionOptions theConnection = new ConnectionOptions(); theConnection.Username = conDet.User; theConnection.Password =
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);
我已经检查了我的机器和服务器上的安全性,两个名称空间具有相同的安全设置。知道发生了什么事吗
谢谢。您使用了错误的命名空间,WMI类在
root\cimv2
中定义
因此,您必须将代码重写为
ManagementScope theScope = new ManagementScope(String.Format(@"\\{0}\root\cimv2", conDet.Server), theConnection);
你是说我唯一可以连接的名称空间是cimv2?其余的都是禁止的?不,我不是说,每次建立WMI连接时,都必须指定特定的命名空间(作用域)。因此,您可以连接到任何现有命名空间,但使用不同的WMI连接。