如何使用python检查某个进程是否在任务管理器中运行 [英] How to check if some process is running in task manager with python

查看:96
本文介绍了如何使用python检查某个进程是否在任务管理器中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 python 中有一个函数,当某个进程(例如 proc.exe)出现在任务管理器中时,它应该开始运行.
如何使用 python 监控在任务管理器中运行的进程?

解决方案

这里有一些东西,我改编自 微软

<前>导入 win32com.clientstrComputer = "."objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")colItems = objSWbemServices.ExecQuery("Select * from Win32_Process")对于 colItems 中的 objItem:打印名称:",objItem.Name打印文件位置:",objItem.ExecutablePath

这里有很多python和windows的好例子

更新:objItem.ExecutablePath 给出了 exe 的文件位置

I have one function in python which should start running when some process (eg. proc.exe) showed up in tasks manager.
How can I monitor processes running in tasks manager with python?

解决方案

here is something, I've adapted from microsoft

import win32com.client
strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("Select * from Win32_Process")
for objItem in colItems:
   print "Name: ", objItem.Name
   print "File location: ", objItem.ExecutablePath

There is here a lot of nice examples for python and windows

Update: objItem.ExecutablePath gives the file location of the exe

这篇关于如何使用python检查某个进程是否在任务管理器中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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