我的目标:
- 使用参数在远程机器上启动进程(安装应用程序)
- 等待进程完成并在完成时引发事件。
我在这一行收到错误“无法解析的查询
”:
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());
}
}