pywin32 / pywinauto not working properly in remote desktop when it is minimized

蹲街弑〆低调 提交于 2019-12-01 11:30:24

UPD: all practices listed below are compiled into Remote Execution Guide which may be more up-to-date.

The problem with Remote Desktop doesn't depend on the tool. The RDP itself doesn't keep GUI context when it's minimized or disconnected (the same effect takes place when the OS is locked). But the symptoms usually involve .click_input() and .type_keys() / keyboard.SendKeys() methods that are not working without GUI context.

The workarounds for minimized RDP problem:

  1. Switch RDP to windowed mode (non full screen), run the script there and quickly switch to local machine. Now you can work normally. This is the simplest way for manual run.

  2. Install VNC server software on remote machine (I used TightVNC) and VNC client (also TightVNC) on local one. You may require updating video card drivers on remote machine if you see black screen. You also must reboot remote host if RDP was used at least once. The main benefit: you can even disconnect from remote host but TightVNC will always keep GUI context. This is more suitable for automatic runs (Jenkins agent must run in this active desktop, it can't be run as a service at all). Another virtual desktop environment like Citrix might be OK for this purpose, but I have no personal experience with that.

  3. RDP (mstsc command) has some parameter to unbind virtual remote desktop from current connection (don't remember right now). Additional tools for automatic remote run may include psexec or Ansible with psexec plugin.


If the main window is not found for this application (process PID) maybe saplogon.exe spawns another process with the target window. Then you have to do app = Application().connect(title="SAP Logon 740", timeout=10) to bind with correct process ID. This is pretty common problem for such launchers.


ctypes.ArgumentError is more interesting. Please provide the full traceback of the error. I suspect this can be fixed on pywinauto side. This kind of error may happen because other Python libraries use ctypes incorrect way, but it can be workarounded probably.


If LogOn button can't be found using default "win32" backend, you may try Application(backend="uia").connect(...). The difference is explained in the Getting Started Guide.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!