我的目标:
我在此行收到错误“无法解析的查询”:
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());
}
}
答案 0 :(得分:0)
你的WQL中有一个拼写错误 替换这一行
string queryString = "SELECT * From WIN32_ProcessStopTrace WHERE ProcessID= outParams['ProcessID']";
这一个
string queryString = String.Format("SELECT * From WIN32_ProcessStopTrace WHERE ProcessID={0}",outParams['ProcessID']);