I have a an autohotkey script that automates an Import Wizard GUI. When I RDP into the machine where this script resides I can run the script it works beautifully. The script runs on a 10 minutes schedule. If I have RDP’d into the machine at the time the schedule happens to run, I can see that the script runs beautifully.
When I log out of RDP (or even just minimize the window) the script runs on schedule and hangs at the very first window in the Import Wizard. If I go back to RDP I see that window sitting there and I see my script hanging as it waits for the next window to appear. If I click OK on the open window (which is exactly what the ahk script does) then my script continues and runs fine.
tldr: my auto hot key script only works when I’m watching!
Here’s some code …
#NoTrayIcon
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
saexe_file = C:\test.exe
company_file = Z:\ABC.SAI
import_file = D:\test.imp
Run, %saexe_file%
WinWait Simply Accounting Import - Select Company
WinActivate
Send %company_file%{Enter}
; IT HANGS HERE
WinWait Simply Accounting Import - Select File to Import from
WinActivate, Simply Accounting Import - Select File to Import from
Send %import_file%{Enter}
EDIT 07-12-2013: found the solution:
Instead of disconnecting from RDP, run this batch file …
for /f "usebackq skip=1 tokens=3" %%i in (query user %USERNAME%) do %windir%\System32\tscon.exe %%i /dest:console