[英]C# WMI Unparsable query
My goal: 我的目标:
I'm getting an error " Unparseable query " at this line: 我在此行收到错误“ 无法解析的查询 ”:
var watcher = manWatch.WaitForNextEvent(); var watcher = manWatch.WaitForNextEvent();
I have a database of about 2xx different applications i can install from using this method. 我有大约2xx个不同应用程序的数据库,我可以使用此方法进行安装。 Not every application gives me this error during install.
并非每个应用程序在安装过程中都会出现此错误。 Some are succesful and some not.
有些成功,有些则没有。 I do believe it's the way I'm going about getting the event.
我确实相信这是我要参加的活动的方式。 Any ideas?
有任何想法吗?
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());
}
}
You had a typo in your WQL sentece replace this line 您的WQL情节中有错别字,请替换此行
string queryString = "SELECT * From WIN32_ProcessStopTrace WHERE ProcessID= outParams['ProcessID']";
by this one 通过这个
string queryString = String.Format("SELECT * From WIN32_ProcessStopTrace WHERE ProcessID={0}",outParams['ProcessID']);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.