如何获取我打开的所有程序的列表?

问题描述 投票:0回答:0

基本上我正在尝试构建简单的应用程序拦截器,但我尝试了很多解决方案,但它们总是返回窗口句柄而不是正在运行的程序的名称

我运行程序,这是输出 提出一个公开问题 - Stack Overflow - Google Chrome

我只想得到程序的名称所以谷歌浏览器

import pyautogui
import AppOpener

# blocked window
blocked = "Microsoft Edge"

#this prints list of all the window.
windows = pyautogui.getAllWindows()

for window in windows:
    app = window.title


    app_split_list = str(app).split("-")
# the reason why im splitting it is because the window.title is in format like this:
New tab - Personal - Microsoft​ Edge


    for item in app_split_list:
        print(item)
        if blocked in item:
            print("found")
            AppOpener.close(blocked)
            break

#this didnt work because the getAllWindows() returned New tab - Personal - Microsoft​ Edge ( Microsoft Edge is with 2 spaces in between so it didnt got recognized.)

我试过使用 pyautogui 模块,但我无法弄清楚如何获得确切的程序,而不是窗口句柄。

我运行程序,这是输出: 提出一个公开问题 - Stack Overflow - Google Chrome YouTube - 个人 - Microsoft Edge

如您所见,它的程序名称在末尾,但是有没有办法只获取程序名称。我在它周围制作了应用程序块,但通常它不起作用并且不会将窗口句柄识别为程序

python pyautogui
© www.soinside.com 2019 - 2024. All rights reserved.