使用Python自动单击Windows安全弹出窗口

2024-05-19 21:38:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用win32gui库获取Windows安全弹出窗口的句柄,并使用win32con在其中单击“Install”按钮,但没有成功。以前有人在Python中成功地做到了这一点吗?在

我知道我总是可以安装发布者的证书,并且可以永远使用它,但是我需要考虑所有可能弹出的安全警告。在

这是可以做到的,因为我已经成功地在VBScript中完成了,但我现在需要Python。在

enter image description here。在

def window_handle(Title):
    handle = win32gui.FindWindowEx(0, 0, 0, Title)
    return handle


def click_btn(hWnd, Button):
    hbutton = win32gui.FindWindowEx(hWnd, 0, "Button", Button)
    if hbutton != 0:
        win32api.PostMessage(hbutton, win32con.WM_LBUTTONDOWN, 0, 0)
        win32api.PostMessage(hbutton, win32con.WM_LBUTTONUP, 0, 0)
        return True
    return None

hWnd = window_handle("Windows Security")
click_btn(hWnd, "&Install")

Tags: installreturntitlewindowsdefbuttonwindowclick