吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2577|回复: 5
收起左侧

[Python 转载] Python 关闭某个打开的软件或目录

  [复制链接]
雪辉 发表于 2021-5-21 01:04
本帖最后由 雪辉 于 2022-5-31 15:24 编辑

[Python] 纯文本查看 复制代码
# 用于禁止用户打开指定的文件或目录
import win32gui
import win32con
import time

def exe_is_active():
    while True:
        time.sleep(0.2)
        try:
            # 关闭文件或目录,使用模糊查询
            hld = FindWinHwnd(u" - 脚本")
            if str(hld) != "0":
                time.sleep(0.2)
                win32gui.PostMessage(hld, win32con.WM_CLOSE, 0, 0)
                time.sleep(0.1)
                print("已关闭txt")

            # 关闭文件或目录,精准查询
            hld = win32gui.FindWindow(None, u"公用")
            if str(hld) != "0":
                time.sleep(0.2)
                win32gui.PostMessage(hld, win32con.WM_CLOSE, 0, 0)
                time.sleep(0.1)
                print("已关闭目录")
        except:
            print("速度过快报错")

# 模糊查询
def FindWinHwnd(title, top=True):
    titles = []
    def foo(hwnd, mouse):
        if top:
            if win32gui.IsWindow(hwnd) and win32gui.IsWindowEnabled(hwnd) and win32gui.IsWindowVisible(hwnd):
                if title in win32gui.GetWindowText(hwnd):
                    titles.append(hwnd)
                    return titles[0]
        else:
            if title in win32gui.GetWindowText(hwnd):
                titles.append(hwnd)
    win32gui.EnumWindows(foo, 0)
    if titles:
        return titles[0]
    else:
        return 0


if __name__ == '__main__':
    exe_is_active()

免费评分

参与人数 4吾爱币 +4 热心值 +2 收起 理由
Ljh666 + 1 热心回复!
wzzjnb2006 + 1 + 1 谢谢@Thanks!
azcolf + 1 + 1 热心回复!
How123 + 1 谢谢@Thanks!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

link2333 发表于 2021-5-21 01:11
谢谢楼主分享啦
Boyfri_End 发表于 2021-5-21 01:12
18337045351 发表于 2021-5-21 01:48
jjl 发表于 2021-5-21 08:43
正在学习中,谢谢分享
cyl279 发表于 2021-5-21 09:22
感谢分享
woshidyj 发表于 2021-5-21 10:29
学习学习,感谢分分享
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-19 10:28

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表