C# 中一个简单查询的 WMI 错误 [英] WMI error with a simple query in C#
本文介绍了C# 中一个简单查询的 WMI 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 Windows 2000 上使用此代码:
I am trying to use this code on Windows 2000:
foreach (Process p in Process.GetProcesses())
{
if (p.MainModule.FileName.EndsWith("calc.exe"))
{
using (ManagementObjectSearcher mos =
new ManagementObjectSearcher(
"SELECT CommandLine,ExecutablePath
FROM Win32_Process WHERE ProcessId=" + p.Id.ToString()))
{
using (ManagementObjectCollection moc = mos.Get())
{
foreach (ManagementObject mo in moc)
{
MessageBox.Show((string)mo["CommandLine"]);
return;
}
}
}
}
}
这适用于 Windows XP 及更高版本,但在 Windows 2000 上失败并显示无效查询"错误.根据 MSDN,Win32_Process 对象是Windows 2000 及更高版本支持,所以我不确定我做错了什么.任何帮助将不胜感激.
This works on Windows XP and higher, but fails on Windows 2000 with an "Invalid query" error. According to MSDN, the Win32_Process object is supported on Windows 2000 and higher, so I'm not sure what I'm doing wrong. Any help would be much appreciated.
推荐答案
对不起大家.我刚刚意识到CommandLine"字段仅适用于 Windows XP 及更高版本.问题解决了.
Sorry everyone. I just realized that the "CommandLine" field is only in Windows XP and higher. Problem solved.
这篇关于C# 中一个简单查询的 WMI 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文