Running AHK manipulating GUI of application on disconnected server (RDP)
Posted: 12 Sep 2021, 12:14
So I have a cloud Windows 2012 R2 server that I connect to via RDP, and disconnect from, of course, after I am done. My AHK script runs as a scheduled task in the middle of the night and it is not able to automate clicks in the GUI.
On this server I am trying to send keys to a Chrome window (which another VB application opens first) to download a file. This is the code, and it works when logged into the machine:
It runs fine on my local Windows 10 PC, as well it also runs fine on the server when I am logged in and looking at the Windows GUI. It does not work when run from Task Scheduler when I am disconnected.
If I disconnect from the server using this in a BAT file, it seems to keep the console open. But not when I disconnect normally (always using this BAT file to disconnect is not a viable option).
This has to be a common problem for AHK automation on a cloud or other similar remote-only server or PC. I can't find any viable solution.
Is there some way to force the console/GUI back on in some way? I have completely control of the server to do as I wish.
On this server I am trying to send keys to a Chrome window (which another VB application opens first) to download a file. This is the code, and it works when logged into the machine:
Code: Select all
SetTitleMatchMode, 2
WinWait, Ads Manager - Reporting, ,120
if ErrorLevel
{
MsgBox, WinWait timed out.
return
}
else
{
Sleep 10000
WinActivate, Ads Manager - Reporting
;WinMaximize
Sleep 2000
SendInput, {tab 20}
SendInput, {enter}
Sleep 1000
SendInput, {enter}
}
It runs fine on my local Windows 10 PC, as well it also runs fine on the server when I am logged in and looking at the Windows GUI. It does not work when run from Task Scheduler when I am disconnected.
If I disconnect from the server using this in a BAT file, it seems to keep the console open. But not when I disconnect normally (always using this BAT file to disconnect is not a viable option).
Code: Select all
for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (tscon.exe %%s /dest:console)
Is there some way to force the console/GUI back on in some way? I have completely control of the server to do as I wish.