I'm trying to get all the processes and applications that are currently running using Python on Windows 7

痴心易碎 提交于 2019-12-24 09:53:22

问题


I'm currently running Windows 7, and I'd like to be able to check whats going on programaticly using Python. How would I go about getting all the currently runing processes and applications?


回答1:


Get the WMI module and then check out this cookbook for some simple examples. Note this is not the most efficient way, talking to the win32 api with ctypes is faster but much much more legwork.

To list all currently running processes:

import wmi
c = wmi.WMI ()

for process in c.Win32_Process ():
    print process.ProcessId, process.Name



回答2:


The psutil module may be helpful. For instance:

import psutil 

[psutil.Process(pid).name for pid in psutil.get_pid_list()]


来源:https://stackoverflow.com/questions/5971743/im-trying-to-get-all-the-processes-and-applications-that-are-currently-running

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!