我在控制台程序中运行以下代码: -
var query = string.Format("select * from Win32_Process");
var searcher = new ManagementObjectSearcher(query);
var collection = searcher.Get();
foreach (ManagementObject o in collection)
{
if(o["CommandLine"] == null) continue;
if (o["ProcessId"] == null) continue;
if( o["ExecutionState"] == null)continue;
var executionState =o["ExecutionState"].ToString();
var commandLine = o["CommandLine"].ToString();
var processId = o["ProcessId"];
Console.WriteLine("{0}: {1} [{2}]",
processId,
executionState,
commandLine);
}
但是,执行状态始终为null。谁知道为什么?我尝试过以管理员身份运行。
使用进程资源管理器,我肯定有一个处于暂停状态的进程: -