[英]Find suspended windows processes using WMI, why is "ExecutionState" always null?
I'm running the following code in a console program:-我在控制台程序中运行以下代码:-
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);
}
However the Execution state is always null. Anyone know why?然而,执行 state 始终是 null。有人知道为什么吗? I've tried running as Administrator.
我试过以管理员身份运行。
using process explorer, I definitely have a process in a suspended state:-使用进程资源管理器,我肯定有一个进程处于暂停状态 state:-
Looks like ExecutionState
isn't implemented and is always null
. 看起来
ExecutionState
没有实现,并且始终为null
。 The official docs don't mention it, but third-party docs do. 官方文档没有提到它,但第三方文档也没有。
You can use 'ThreadCount' to test if it is 0. Zombie processes have 0 because any normal process has at least 1.您可以使用“ThreadCount”来测试它是否为 0。僵尸进程有 0,因为任何正常进程至少有 1。
Another possibility is to use 'OpenProcess' and ask 'GetExitCodeProcess'.另一种可能性是使用“OpenProcess”并询问“GetExitCodeProcess”。 If the process is running it will return 'STILL_ACTIVE' while Zombies will return their exit code.
如果进程正在运行,它将返回“STILL_ACTIVE”,而 Zombies 将返回它们的退出代码。 But this is a little bit slower than the first method.
但这比第一种方法慢一点。 A bit unclear what happens if a process sets his exit code to 'STILL_ACTIVE'.
有点不清楚如果一个进程将他的退出代码设置为“STILL_ACTIVE”会发生什么。 I guess Win32 won't allow that.
我猜 Win32 不允许这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.