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.
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.
Related
I made a python script that runs a graphical automation using pyautogui (mouse movements) over a huge number of PDFs.
The automation appears to need an active display, for the mouse movements and the PDF to be opened.
If I connect to the Azure VM (with Windows OS) with SSH and start the python script, I get an error from pyautogui as below:
pyautogui.FailSafeException:
PyAutoGUI fail-safe triggered from mouse moving to a corner of the screen.
To disable this fail-safe, set pyautogui.FAILSAFE to False.
DISABLING FAIL-SAFE IS NOT RECOMMENDED.
I have tried with the failsafe disable and still it doesn't work.
As I have read, this happens because there is no active display opened.
If I connect to the VM using RDP, the automation starts and works as expect until I minimize or close the window. When I do that I get the same failsafe error from pyautogui.
But I cannot keep the window open, because I would need to start the same automation on 16 more VMs.
Is there a way to run such graphical automations in Azure VMs or any other similar solution? Docker maybe?
Is there any solution to run or host VM machines with permanent active display opened? Is something like this possible?
I ended up using Virtual Box.
I first created one VM with the needed software and files.
You can start the VM in headless mode. Then show the VM in order to log in to Windows and start the automation script. Then you can close the VM window and let it run in the background. The graphical automation will still run ok in that case. PyAutoGUI won't crash as if there were no active display.
I cloned the original VM 16 times and split the work evenly between the VMs.
Using ssh I am able to connect to each VM and monitor the status of the automations.
It would be great if there were a solution similar to kubernetes that could help with the deployment of such automations and with the monitoring of the status, but until then this is ok.
I'm having a pc that i have a python script on it that uses Gui (moves the mouse while searching some opjects). - PC #1
I need to operate this script from another pc (PC #2) in an automation script (that process is just one of the steps, which repeats a lot, but the only one i have issue with).
both are operating with windows.
PC1 can get connection from SSH. and i need to open this script using the PC2. But this script doesn't operate due to gui i think. it's similar to why for example i can't open Matlab or any othe app in PC1 using SSH.
Any way to do it?
Wasn't able to find an answer online. at the moment i use SSH from PC2 (connected using python) to be used with PC1 to run a specific gui locally.
I have been facing issue with automation execution of my script on one of the VM. I have automated the functionality of Saving a Document which is ideally a Windows Designed UI. I have tried using various technologies/tools like AutoIT, Python, Sikuli but the script halts if VM is minimized. It works perfectly fine is VM is open via RDP and I can see runtime execution. But If I minimize the RDP, the script halts at 'Save As' dialog box, none of the send keys (Cntrl+s) or (Enter) work via AutoIt script. Please help with some solution so as to have successfully execution of script even in minimized mode.
The reason why your script fails when it gets executed over a minimized RDP session is quite simple. GUI automation/testing tools need to have an unlocked, active desktop - otherwise the operation system thinks that it doesn't need to actually render GUI operations (which is time consuming) since there no user can that can see the rendered graphical user interface anyway. And programs don't communicate via GUIs normally ...
This is why QF-Test and other GUI automation/testing tools often have a note in their FAQs describing this kind of problem. For example FAQ 14 in the case of QF-Test, see https://www.qfs.de/qf-test-handbuch/lc/manual-en-faq.html
As described in the FAQ 14 on Windows 10 or Windows Server 2016 and in case of an RDP connection you need to modify the Registry. Go to
HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client
and add a new value
RemoteDesktop_SuppressWhenMinimized as DWORD having the value 2
After restarting you will then be able to minimize the RDP connections. However disconnecing or closing the RDP connection will probably still result in a failure.
You could try running tscon.exe RDP-Tcp#0 /dest:console as admin as mentioned here. This will disconnect your RDP connection but should leave all GUI programs running normally on the VM. I have personally used this with autoit on a VM and it worked OK. Of course you will not be able to monitor your script as it runs so this may or may not work for you.
I need to run GUI application on remote windows host and then do some actions with mouse and keyboard. This should be done from local pc without opening any GUI application (for example "Remote Desktop Connection").
So I have a python script on remote server which does all the actions I need (tested on local pc) and I run the script via psexec which successfully opens the GUI application on server.
The problem is that when python tries to programatically move and click mouse it throws an exception because there is no screen.
Actions with keyboard (Ctrl-A, Ctrl-C, Ctrl-V) can be done successfully.
Here is the code that I use to simulate mouse click but as I mentioned it doesn't work on server because there is no actual screen.
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
Can anyone suggest me a solution?
Try connecting directly to user32.dll through ctypes and use mouse controlling functions from there. Perhaps win32types problem is that it is mostly statically linked to MS API. So it is programmed for desktop environment.
Also, you can try pymouse module that you can find on pypi.python.org, of course, which does the same as I suggested above.
I am creating Windows service class in Python that will eventually display a Window when certain conditions are met. Since (as I understand it) services cannot have GUIs, I'm trying to start up a GUI in a seperate process (using subprocess.Popen) when the conditions are right. This isn't working, presumably because the child process has the same privileges as the service.
So how do I start a process from a Python Windows Service that has the ability to display GUIs on the screen?
If you give your Service the Allow service to interact with desktop permission it will be able to create windows without the need to launch a subprocess.
As mentioned in this answer, you may have to (eventually) transition to a client-server model since Windows Vista and later no longer support direct interaction with users.