C#WMI不可解析查询
我的目标是:C#WMI不可解析查询,c#,wmi,wmi-query,C#,Wmi,Wmi Query,我的目标是: 使用params在远程计算机上启动进程(安装应用程序) 等待进程完成,并在完成时抛出事件 我在这一行收到一个错误“不可解析的查询”: var watcher=manWatch.WaitForNextEvent() 我有一个大约2xx不同应用程序的数据库,我可以使用这种方法安装。并非每个应用程序在安装过程中都会出现此错误。有些是成功的,有些不是。我相信这是我获得比赛的方式。有什么想法吗 private void StartAppAction(string PCName,
- 使用params在远程计算机上启动进程(安装应用程序)
- 等待进程完成,并在完成时抛出事件
var watcher=manWatch.WaitForNextEvent() 我有一个大约2xx不同应用程序的数据库,我可以使用这种方法安装。并非每个应用程序在安装过程中都会出现此错误。有些是成功的,有些不是。我相信这是我获得比赛的方式。有什么想法吗
private void StartAppAction(string PCName, string Command)
{
string Params = @"\\" + PCName + @"\C$\SoftwareInstall\" + Command;
ConnectionOptions conOpt = new ConnectionOptions();
conOpt.Impersonation = ImpersonationLevel.Impersonate;
conOpt.Authentication = AuthenticationLevel.Default;
conOpt.EnablePrivileges = true;
ManagementScope manScope = new ManagementScope(String.Format(@"\\{0}\ROOT\CIMV2", PCName), conOpt);
manScope.Connect();
ObjectGetOptions objGetOpt = new ObjectGetOptions();
ManagementPath manPath = new ManagementPath("Win32_Process");
ManagementClass manClass = new ManagementClass(manScope, manPath, objGetOpt);
ManagementBaseObject inParams = manClass.GetMethodParameters("Create");
inParams["CommandLine"] = Params;
ManagementBaseObject outParams = manClass.InvokeMethod("Create", inParams, null);
string queryString = "SELECT * From WIN32_ProcessStopTrace WHERE ProcessID= outParams['ProcessID']";
WqlEventQuery wqlQuery = new WqlEventQuery(queryString);
ManagementEventWatcher manWatch = new ManagementEventWatcher(@"\\" + PCName + @"\root\CIMV2", "SELECT * From WIN32_ProcessStopTrace WHERE ProcessID=" + outParams["ProcessID"]);
var watcher = manWatch.WaitForNextEvent();
if (watcher["ExitStatus"].ToString() == "0")
{
MessageBox.Show("Remote Exection Finished Succesfully with ExitCode 0");
}
else
{
MessageBox.Show("Remote Exection exited with the code of " + watcher["ExitStatus"].ToString());
}
}
你的WQL语句有一个输入错误 更换这条线
string queryString = "SELECT * From WIN32_ProcessStopTrace WHERE ProcessID= outParams['ProcessID']";
通过这个
string queryString = String.Format("SELECT * From WIN32_ProcessStopTrace WHERE ProcessID={0}",outParams['ProcessID']);
感谢@RRUZ的回复。刚刚用你的代码替换了我的代码,我仍然遇到同样的问题。我还必须在outParams[“ProcessID”]部分添加双引号。