【发布时间】: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);
我已经检查了我的机器和服务器上的安全性,两个命名空间具有相同的安全性设置。有什么想法吗?
谢谢。
【问题讨论】: