Windows – How to keep an RDP session alive

remote desktopwindows 10

How to keep an RDP session alive?

Yes, I know this question has been asked before, but all the solutions I have read and tried do not work in a locked-down environment in which the domain-level settings are tightly controlled, and even machine-level group policies are partially locked down.

So here is my specific scenario. My workstation is Windows 10, and I regularly RDP into another Windows 10 machine, 20 miles away, over a VPN. This RDP session auto-closes in a very short time of no activity, probably 30 minutes or something. I am unable to change that duration, I don't have permissions, and my IT people will not change it.

Here is the message I receive when my session is forcibly closed by the powers that be, after only 30 minutes of not being actively inside the remote PC via RDP doing something:

Your Remote Desktop Services session ended because the remote computer
didn't receive any input from you.

enter image description here

I have tried the following, without success:

I simply want to keep my RD session alive until I intentionally disconnect it. There must be some way, some hack, some tool, something that actually works.

Please help. Thanks in advance.

Local machine: Win10 Pro 1809
Remote machine (physical hardware, not VM): Win10 Enterprise 1909

Best Answer

The following script uses the free AutoHotkey.

The script checks every 10 minutes (600000 milliseconds) for computer inactivity. It then searches for all Remote Desktop windows by title, and for each it will set the RDP window to be the active window and will send it a click in the middle of its screen and for good measure the Enter key.

SetTitleMatchMode, 2
Loop
{
    if A_TimeIdle >= 600000
    {
        WinGet, id, List, Remote Desktop Connection
        Loop, %id%
        {
            this_id := id%A_Index%
            WinGetTitle, this_title, ahk_id %this_id%
            TrayTip, Found RDP session, %this_title%, 2, 17
            ControlSend , , {Enter}, ahk_id %this_id%
        }
    }
    Sleep, 600000
}
return

This script was tested on a Windows 10 computer with RDP to a Windows 10 VM. For some unknown reason, AutoHotkey is unable to re-minimize the RDP window and re-activate the previously active window, so RDP stays active.

After installing AutoHotKey, put the above text in a .ahk file and double-click it to test. You may stop the script by right-click on the green H icon in the traybar and choosing Exit. To have it run on login, place it in the Startup group at C:\Users\USER-NAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup.

Related Question