在IronPython中使用ManagementClass.Getinstances()
我有一个使用IronPython的脚本,它通过WMI来查找当前正在运行的进程。代码大致是这样的:
import clr
clr.AddReference('System.Management')
from System.Management import ManagementClass
from System import Array
mc = ManagementClass('Win32_Processes')
procs = mc.GetInstances()
在最后一行,我调用了GetInstances()
这个方法,但出现了以下错误:
Traceback (most recent call first):
File "<stdin>", line 1, in <module>
SystemError: Not Found
我不明白到底是什么没有找到?!我觉得我可能需要传递一个ManagementOperationObserver
和一个EnumerationOptions
的实例给GetInstance()
,但是我不明白为什么需要这样做,因为ManagementClass
中有一个Getinstance()
的方法可以用。
1 个回答
1
我觉得唯一的问题是 'Win32_Processes' 写错了,应该是 'Win32_Process'。这样写似乎就可以了:
>>> mc = ManagementClass('Win32_Process')
>>> procs = mc.GetInstances()
>>> for p in procs:
... print p['Name']
...
System Idle Process
System
smss.exe
(etc)