任何人都知道为什么我的查询"select Name, ProcessID, Caption from Win32_Process where ProcessId='" + processIds[index] + "'"
返回
Column 'Name' does not belong to table Win32_Process
在我的程序 C# 中。
当我执行时在powershell中
Get-WmiObject -query "select Name, ProcessID, Caption from win32_process"
其作品 !
String queryString = "select Name, ProcessID, Caption from Win32_Process where ProcessId='" + processIds[index] + "'";
SelectQuery query = new SelectQuery(queryString);
ConnectionOptions options = new ConnectionOptions();
options.Authentication = System.Management.AuthenticationLevel.PacketPrivacy;
ManagementScope scope = new System.Management.ManagementScope("\\root\\cimv2");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
try
{
ManagementObjectCollection processes = searcher.Get();
DataTable result = new DataTable();
foreach (ManagementObject mo in processes)
{
DataRow row = result.NewRow();
if (mo["Name"] != null)
row["Name"] = mo["Name"].ToString();
row["ProcessId"] = Convert.ToInt32(mo["ProcessId"]);
if (mo["Caption"] != null)
row["Caption"] = mo["Caption"].ToString();
result.Rows.Add(row);
}
谢谢你的帮助