I want to check if a specific program is running (not a python file, but e.g. an executable) and I don't really have an idea how to do it.
I have tried using Window.get_all_windows()
from dragonfly (see code sample below) but it returns a list of objects I can't really work with.
#Python 3.7
from dragonfly import Window as win
open_programs_list = win.get_all_windows()
print(open_programs_list)
I really much appreciate your time and help.
答案 0 :(得分:0)
import win32com.client
wmi=win32com.client.GetObject('winmgmts:')
program_name = "chrome.exe"
for p in wmi.InstancesOf('win32_process'):
# print(p.Name)
if p.Name == program_name:
print("Ok")
上面的代码将检查所有当前正在运行的进程,并尝试将其名称与program_name
变量进行匹配。将变量program_name
的值更改为要检查的程序的名称,是否正在运行。
注释:-
p.Name == program_name
将
对于一个给定的名称,必须多次正确。因此,确定将被打印几次chrome.exe
和Chrome.exe
的对待方式有所不同,因此请在为客户提供价值的同时注意案例
program_name
变量。