使用 Python 进行 Windows 进程管理 [英] Windows process management using Python
本文介绍了使用 Python 进行 Windows 进程管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一个脚本来检查特定进程是否正在运行,如果未找到则返回某些内容.我知道这可以使用 subprocess 来完成,但有没有更简单的方法来做到这一点?
I need a script that check if a particular process is running and return something if not found. I know that this can be done using subprocess, but is there a simpler way to do it?
推荐答案
在 Windows 上,您可以使用 WMI:
On Windows, you can use WMI:
import win32com.client
def find_process(name):
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(".", "root\cimv2")
colItems = objSWbemServices.ExecQuery(
"Select * from Win32_Process where Caption = '{0}'".format(name))
return len(colItems)
print find_process("SciTE.exe")
这篇关于使用 Python 进行 Windows 进程管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文