我正在尝试获取当前在 Windows 7 上使用 Python 运行的所有进程和应用程序 [英] I'm trying to get all the processes and applications that are currently running using Python on Windows 7

查看:81
本文介绍了我正在尝试获取当前在 Windows 7 上使用 Python 运行的所有进程和应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前运行的是 Windows 7,我希望能够使用 Python 以编程方式检查发生了什么.我将如何获取所有当前正在运行的进程和应用程序?

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?

推荐答案

获取 WMI 模块 然后查看此食谱以获取一些简单示例.请注意,这不是最有效的方法,使用 ctypes 与 win32 api 通信速度更快,但需要更多的跑腿工作.

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

这篇关于我正在尝试获取当前在 Windows 7 上使用 Python 运行的所有进程和应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆