I want to run pyautogui without remote connection on Windows 10 in the cloud

Asked 2 years ago, Updated 2 years ago, 287 views

I'm trying to automate my work using pyautogui in windows built on the cloud, but even if I start pyautogui on a session logged in with a remote connection, if I disconnect (disconnect) the remote connection during execution, the pyautogui process will not work or end with an error.
Code ↓

import time
import pyautogui aspg

pg.hotkey('alt','tab')#here and
for i in range (10):
    pg.press(str(i))#This line is not processed
    time.sleep(1)

Is there a way to keep pyautogui running even if you disconnect from the remote connection, or to run pyautogui without a remote connection?

■Environment
Azure VM windows 10
python 3.9.7
PyAutoGUI 0.9.53

python windows azure pyautogui

2022-09-30 16:34

1 Answers

If you are "disconnecting" a remote connection, it says, "Programs on the remote computer will continue to run after disconnecting." In fact, these issues and pywinauto documents indicate that the GUI automation operation will fail if disconnected in RDP sessions.

Windows:if you remote desktop into the PC and exit the remote session, pyautogui doesnt work#34
Unable to run pyautogui scripts from remote headless server, I can run them fine from the linux machine #87
Roadmap:Remote/headless desktops#133
Issue as a development theme is standing, but it doesn't seem to be realized.

Remote Execution Guide-pywinauto

Windows Remote Desktop features
Remote Desktop (RDP) offers virtual active desktop to remote machine with Windows OS.There are 2 potential issues:

  • If RDP window is minimized, there is no active desktop on remote PC by default.
  • If RDP is disconnected, the desktop is locked out.

In both cases any GUI automation jobs will fail (if you don't use some tracks descriptive below).The workarounds are well described in TestComplete documentation:

The following are possible options:There may be other things, but I think we need to experiment with them.

  • Launch two Windows images and continue to log in to the machine running pyautogui from the other side: what you see in pyautogui #34 comment
  • Use another remote connection software that does not cause problems when disconnected
    • Terminals-Origin/Terminals: What was in the comment of pyautogui#34
    • VNC Server software:from pywinauto documentation
    • Try something experimental from pyautogui#133
  • Terminals-Origin/Terminals: What was in the comment of pyautogui#34
  • VNC Server software:from pywinauto documentation
  • Try something experimental from pyautogui#133

Note:

By the way, do you have any idea what to trigger when you run pyautogui without a remote connection?
It doesn't seem to depend on anyone's work because it's not connected.

For example, if you have a Q&A and an article like this, you might want to set the VM to auto-logon, register it in the startup folder at that logon, or register it in the Task Scheduler so that programs and scripts run.
I need to be in complete control of VM

The other option is to configure automatic logon
https://support.microsoft.com/en-us/help/324737/how-to-turn-on-automatic-logon-in-windows
and use a script or Task Scheduler to start up your application.

See above in Japanese
Enable auto-logon on the device Windows

Auto-Start (and Auto-Run?) Configuration Example Article
Tried autostarting Azure VM


2022-09-30 16:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.