我尝试让Windows任务计划程序在我登录时使用pywinauto自动执行应用程序,但计算机已切换到其他用户。我目前有:
from time import sleep
from pywinauto.application import Application
app = Application(backend='uia').connect(path='program.exe')
sleep(5)
if 'System Administration' in app.top_window().window_text():
app.top_window().SignOut.click()
sleep(5)
app.top_window().print_control_identifiers(filename='controls.txt')
此时,controls.txt具有:
Control Identifiers:
Dialog - 'System Administration - V6.0.3' (L448, T158, R1471, B922)
[u'System Administration - V6.0.31', u'System Administration - V6.0.30', u'System Administration - V6.0.3', u'System Administration - V6.0.3Dialog', u'Dialog']
child_window(title="System Administration - V6.0.3", control_type="Window")
|
...
|
| Button - 'Sign out' (L980, T399, R1120, B444)
| ['Button8', u'Sign out', u'Sign outButton']
| child_window(title="Sign out", control_type="Button")
|
表示“退出”'按钮没有被点击,因为这应该是下一组菜单。但是,让我感到困惑的是,如果我登录并观看应用程序,那么一切都正常:点击按钮,应用程序进入下一组菜单。
我尝试过的其他事情:
pywinauto.actionlogger.enable()
导致:
2018-05-06 16:15:15,145;INFO
Invoked button "Sign out"
(但仍然没有点击按钮)
app.top_window().SignOut.click_input()
导致:
2018-05-07 12:00:11,730;ERROR
Traceback (most recent call last):
File "myscript.py", line 7, in <module>
app.top_window().SignOut.click_input()
File "C:\Python27\lib\site-packages\pywinauto\base_wrapper.py", line 671, in click_input
key_down=key_down, key_up=key_up)
File "C:\Python27\lib\site-packages\pywinauto\mouse.py", line 125, in _perform_click_input
win32api.SetCursorPos((coords[0], coords[1]))
error: (0, 'SetCursorPos', 'No error message is available')
我不知道这意味着什么。拥有任务计划程序&#34;以最高权限运行&#34;结果:
2018-05-08 08:45:05,908;ERROR
Traceback (most recent call last):
File "myscript.py", line 4, in <module>
app = Application(backend='uia').connect(path='program.exe')
File "C:\Python27\lib\site-packages\pywinauto\application.py", line 955, in connect
self.__warn_incorrect_bitness()
File "C:\Python27\lib\site-packages\pywinauto\application.py", line 1028, in __warn_incorrect_bitness
if self.backend.name == 'win32' and self.is64bit() != is_x64_Python():
File "C:\Python27\lib\site-packages\pywinauto\application.py", line 1043, in is64bit
return handleprops.is64bitprocess(self.process)
File "C:\Python27\lib\site-packages\pywinauto\handleprops.py", line 172, in is64bitprocess
phndl = win32api.OpenProcess(win32con.MAXIMUM_ALLOWED, 0, process_id)
error: (5, 'OpenProcess', 'Access is denied.')
(这也令人困惑,因为Python和程序都是32位。)
当我切换到其他用户帐户时,如何让pywinauto点击按钮?
答案 0 :(得分:0)
当Windows用户被锁定时,您没有活动桌面。因此任何GUI自动化工具都不起作用。这是操作系统限制。您应该在窗口模式下使用RDP的VM或远程计算机(非最小化)。 VNC服务器软件可以替换RDP,并且可以始终保持活动桌面的断开连接(如VNC服务器)。或者应该设置特殊的mstsc设置以允许最小化。
此UC安全确认也可以看到此SetCursorPos问题。这也是OS设计的。
P.S。确保以管理员身份运行脚本。目前这些问题是沉默的,但0.6.5会警告权限不足。