列出 64 位 Windows 上正在运行的进程 [英] List running processes on 64-bit Windows
问题描述
我正在编写一个小 Python 脚本,它将从我正在运行的 Windows 虚拟机中获取信息.
I amm writing a little python script that will grab information from VMs of Windows that I am running.
目前我可以使用以下方法列出 32 位 XP 机器上的进程:
At the moment I can list the processes on a 32bit XP machine with the following method:
http://code.activestate.com/recipes/305279/
是否有可能以某种方式检测正在运行的 Windows 版本并执行不同的方法来获取 64 位机器上的进程,我正在尝试从 64 位 Vista 和 64 位 Windows 7 获取进程.
Is it possible to somehow detect the version of windows running and excute a different method for getting the processes on a 64bit machine, I am trying to get the processes from a 64Bit Vista and 64bit Windows 7.
有什么想法吗?
推荐答案
activestate 上还有另一个方法可以做类似的事情,但使用性能数据助手库 (PDH) 代替.
There is another recipe on activestate that does a similar thing, but uses the Performance Data Helper library (PDH) instead.
我已经在我的 Windows 7 64 位机器上测试了它并且它在那里工作 - 所以大概相同的功能可以在 32 位和 64 位窗口上工作.
I have tested this on my Windows 7 64bit machine and it works there - so presumably the same function will work on both 32bit and 64 bit windows.
您可以在这里找到食谱:http://code.activestate.com/recipes/303339/
You can find the recipe here: http://code.activestate.com/recipes/303339/
另一种方法是使用 WMI,这里有一个在 Python 中使用 wmi 模块:
Another method is using WMI, there is an example here in Python using the wmi module:
http://timgolden.me.uk/python/wmi/cookbook.html
import wmi
c = wmi.WMI ()
for process in c.Win32_Process ():
print process.ProcessId, process.Name
这篇关于列出 64 位 Windows 上正在运行的进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!