In other words: how do I run a GUI app on Windows 10 remotely?
Background: we build and test plugins for third-party CAD engineering software. In order to run tests of our plugins, we need to first activate the CAD software license and this can only be done via GUI (according to the third-party developer) - there is no API. We want to integrate the tests in our CI/CD pipeline, that will include:
- create a virtual machine from an image with the CAD software pre-installed,
- activate the license,
- run tests,
- kill the VM.
The VM needs to be quite powerful, with GPU support, so it would cost a lot of money if we run the VM all the time.
I wrote a very simple Python script with pyautogui to simulate user's mouse and keyboard input. It opens the CAD software, clicks through some windows, puts email and password and thus activates the license. This solution works if I manually connect to the VM through RDP and start the script.
I made the admin user to log in automatically, so that the VM runs logged-in as soon as it is started/rebooted, by changing the registry entry:
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Winlogon
I added my Python script to the autostart (shell:startup) so that it should start when the machine starts. I guess I could also make it a Scheduled Task. Again, it all works when the machine is created manually via Azure Portal.
Here is where the problem starts: I now want to do the same but automatically from Azure Devops pipeline and I need to know when my Python script finished its job.
Using PowerShell/Yaml in Azure Devops pipeline, I create a VM like before, and I want to run my python script in the context of an interactive desktop session. This however does not happen. The script starts, and the owner of the process seems correct (it's my admin user, not SYSTEM), but it actually runs only in the background (no access to the GUI).
In order to test my assumption, I run a simple command like this just to start MS Paint:
Invoke-AzVMRunCommand `
-ResourceGroupName '<my-group>' `
-VMName '<my-vm-name>' `
-CommandId 'RunPowerShellScript' `
-ScriptString "
& mspaint"
or
Invoke-Command -Session $session -ScriptBlock {
& mspaint
}
I would like the MS Paint start in the interactive mode, i.e. I am expecting the Paint window to be open when I connect to that VM via RDP to check the result.
I also used the tscon command to try to change the session I'm interacting with:
tscon.exe 1 /dest:console
But then when I run qwinsta command, I still seem to be in a wrong place:
SESSIONNAME USERNAME ID STATE TYPE DEVICE
>services 0 Disc
console tester 1 Active
31c52344259d4... 65536 Listen
rdp-tcp 65537 Listen
Any suggestions will be highly appreciated!