pythonremote-accesspywinautosetforegroundwindow

Remote Desktop Connection - SetForeground Window not working


I have very similar problem to this one : SetForegroundWindow in Remote Desktop Connection Everything works when I am connected and watching the RDC, but when I'm not.. Nothing happens. I am using python and pywinauto, trying to use SendKeys method : SetForegroundWindow returns 0, the same as GetLastError after that, so I have no idea what might cause the trouble.

Edit: I also tried other methods like BringWindowToTop, or SetActiveWindow, also I tried to sent alt key before changing windows - nothing worked.


Solution

  • If your pywinauto script works on remote machine, it cannot manage RDP window at all because RDP window is on your local machine.

    To prevent lost of GUI context in RDP you do NOT need to minimize RDP window locally. RDP can lose focus safely, but minimizing leads to stop of any GUI related activity.

    It's correct for any GUI automation, not pywinauto only. If you have a lot of test machines, the best way is having 1 master and many slaves. Master host can initiate and keep non-minimized remote sessions, slaves are running GUI automation scripts.