使用WMI查找暂停的Windows进程,为什么" ExecutionState"总是空的?

时间:2014-09-16 03:02:07

标签: c# wmi

我在控制台程序中运行以下代码: -

 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。谁知道为什么?我尝试过以管理员身份运行。

使用进程资源管理器,我肯定有一个处于暂停状态的进程: -

enter image description here

1 个答案:

答案 0 :(得分:5)

看起来ExecutionState未实施且始终为nullofficial docs没有提及,但third-party docs会这样做。