19

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

7 Answers7

7

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 an Enter key input.

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.

harrymc
  • 498,455
5

You can make a session keep-active pretty easy:

Alive.js script:

var WshShell = WScript.CreateObject("WScript.Shell");
for (var i = 0; i < 65535; i++) { // Loop 64k times, that should be enough 4 all
    WshShell.SendKeys('{SCROLLLOCK}');
    WshShell.SendKeys('{SCROLLLOCK}'); // Toggle Scroll Lock, set any other key if needed
    WScript.Sleep(300000); // Wait 5 minutes or whatever time you want (in ms)
}

Active.bat file to run the script:

@color A
@echo Refresh Active.
@Cscript.exe Alive.js
@timeout 1

Start the .bat and that's it.

Overmind
  • 10,308
5

My annoyance was the Remote Desktop session locking the screen after a few minutes due to company set policy. I found the unexpected solution to the problem in a comment for issue 405 of mRemoteNG (Simulate keyboard or mouse move to avoid RDP session idle timeouts). It's a simple AutoHotkey script which you run on your remote machine.

#SingleInstance, force
#Persistent
;in milliseconds - so 30000 would be every 30 seconds
SetTimer, NoSleep, 240000
Return

NoSleep: DllCall( "SetThreadExecutionState", UInt,0x80000003 ) Return

U. Windl
  • 943
2

I just found ImAlive (and keepalive) on github. Both seem to be a "hack" to overcome this issue. They seem similar to mousejiggler and caffeine, but are specifically designed to avoid such RDP inactivity:

ImAlive - Simulates RDP activity to keep idle RDP sessions alive

sapisch
  • 121
1

It should be:

Computer Config/Administrative Templates/Windows Components/Remote Desktop Services/Remote Desktop Session Host/Session Time Limits

But this isn't configured by default so that means someone has configured it, meaning if they find out you're circumventing this policy, they might not like it

0

I use RDP Session Keep Alive:

https://www.codeproject.com/Tips/1174585/RDP-Session-Keep-Alive

xian
  • 101
0

Sorry for the necropost, but found this trying to solve a similar issue - for me, the issue was related to the sleep settings in the windows power configuration.

The symptom was RDP disconnect, the problem was the PC was going to sleep.