Solution to Autohotkey automation failing to work with disconnected Remote Desktop

These are some of the solutions that will allow you to run automation tests with application tools like AutoHotkey and AutoIt on a disconnected remote desktop connection.

Windows automation tool like Autohotkey, AutoIt or other Application testing suite fail to load when using them on the remote desktop. The problem occurs as the Remote Desktop is disconnected, the interface automation tools fail to detect changes and stop working.

There have been some workarounds for this problem. One being a registry hack to add an RemoteDesktop_SuppressWhenMinimized entry to enable automation tools to detect window changes.  While this seems to work, you still need the connection to be active on the minimized remote desktop connection manager.

1. Locate any of the following Registry keys:

  • HKEY_CURRENT_USER/Software/Microsoft/Terminal Server Client(if you want to change the RDC settings for your user account)

2. Create a new DWORD value in this key named RemoteDesktop_SuppressWhenMinimized. Specify 2 as the value data.

Another one is to disconnect the Remote Desktop using tscon.exe as such it doesn’t lock the user account and allows the Window detection in Windows operating system.  This requires you to create a batch file and run it every time before you disconnect your connection. While this may be the simplest way, you might not always be remember to run it. And as you disconnect through regular remote desktop, your tests would have failed or paused until you log back in.

Create a batch file with the following commands and save it to the desktop of the workstation you want to keep unlocked:

START C:\Windows\System32\tscon.exe 0 /dest:console
START C:\Windows\System32\tscon.exe 1 /dest:console
START C:\Windows\System32\tscon.exe 2 /dest:console
START C:\Windows\System32\tscon.exe 2 /dest:console
START C:\Windows\System32\tscon.exe 3 /dest:console
START C:\Windows\System32\tscon.exe 4 /dest:console
START C:\Windows\System32\tscon.exe 5 /dest:console

For AutoHotKey:

Run % "*RunAs C:\Windows\System32\tscon.exe " (A_Index-1) " /dest:console",,HIDE

There’s an alternative I’ve found that works similar to second option we listed above. This is accomplished by applications that connect to the Remote desktop with their own protocols. I have tested it with the Jump Desktop Remote Desktop manager. But this should work on other applications like Teamviewer and Splashtop. As they use their own connection to connect and do not lock the device while you disconnect, the automation tests can run un-interrupted.

Let me know if this works for you.

One comment

  1. This is a good solution except that running tscon.exe typically requires a UAC click. Which is not going to go well in ahk, since it can’t make that click.

    You could disable all UAC prompts for your system but below is a different
    method.

    #1. You create a batch file to run the tscon for the various needed IDs, as you outline above.

    #2. You make a shortcut that uses windows scheduler to run that specific batch file without needing UAC. You can use UAC pass freeware program to do this easily; other possibilities outlined here https://www.techgainer.com/disable-uac-prompts-specific-programs-windows/

    #3. We call schtasks.exe with that scheduled item as below.

    Run, C:WindowsSystem32schtasks.exe /run /tn “UAC passre-logon-console”,,HIDE UseErrorLevel

    You account will (probably?) need administrator level permissions to do this successfully.

Leave a Reply