我正在制作一个无限循环运行的程序,并在 UAC 启动或满足特定条件时报告。我试图通过捕获正在运行的应用程序的窗口标题来检测何时触发 UAC 提示。
我还使用
pyautogui
捕获 UAC 提示窗口的屏幕截图,然后使用 locateOnScreen()
方法找到它,但是当 UAC 启动时 pyautogui 返回与下面提到的完全相同的异常。 pywintypes.error: (1400, 'GetClassName', 'Invalid window handle.')
...
While True:
hWnd = win32gui.GetForegroundWindow()
tWnd = win32gui.GetWindowText(hWnd)
print(tWnd)
time.sleep(1)
...
# Captured screenshot of UAC prompt using keyboard shortcuts and then
# tried to detect it using pyautogui but it also returns None.
img = Image.open(PATH_TO_IMAGE) # using PIL lib
lWnd = pyautogui.locateOnScreen(img)
print(lWnd)
这会抓取每个窗口的标题文本,但一旦启动 UAC 提示符,它就会抛出异常
pywintypes.error: (1400, 'GetClassName', 'Invalid window handle.')
而它应该打印 UAC 提示符的标题,即“用户帐户控制”。
我应该怎样做才能实现这个目标?
Microsoft 允许“屏幕阅读器”阅读 UAC 屏幕。
将您的申请明确为uiAccess="true"
C:\Program Files
)
UAC 对话框。