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
  • I don't know the answer, but if you Edit to include these specifics it might help : What specific Windows 10 version (1803, 1809, etc) is on local and remote? What version of Windows Server is providing the domain? Is the remote Windows 10 machine a physical machine, VM, or something more complicated like Windows Remote Desktop Server or Citrix VDI ? Apr 30, 2020 at 5:46
  • 1
    Added, but I don't know what version of winserver is providing the domain. Apr 30, 2020 at 12:04
  • Check the server for applied group policies. I would assume that some Terminal Server GPOs regarding timeouts are set.
    – Robert
    Apr 30, 2020 at 12:14
  • Robert: Where in GPO are those settings? (And it's likely that I don't have permissions to modify.) Apr 30, 2020 at 15:30
  • Why don't you ping your gateway/server at a regular interval via command line?
    – user1019780
    May 3, 2020 at 16:26

8 Answers 8


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
    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

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.

  • I was very hopeful, but it didn't work. I ran it on local PC (Win10) while I was RDP'd to my remote win10 PC. My RDP session was minimized. The ahk script says it sends TrayTip messages, but I sat here and watched and never saw one. I confirmed it was running, because I can see the green square icon in the tray. May 7, 2020 at 0:09
  • I didn't test when RDP is minimized, I might have to tweak it some more. Does it work on your side when it's not minimized?
    – harrymc
    May 7, 2020 at 6:03
  • And these events won't work for a minimized program, so more work is required.
    – harrymc
    May 7, 2020 at 7:24
  • Found it: While minimized the class-name criteria doesn't apply to the RDP window, so have to search by title. See the updated script.
    – harrymc
    May 7, 2020 at 10:55
  • I'm testing this, but just a note for now, it's fairly resource intensive. Task Manager says it's running constantly, using 3.5% of CPU, and Power Usage bounces constantly between Medium and High. I noticed that you removed the Sleep, 600000 at the bottom - should that come back? May 7, 2020 at 12:47

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}'); // 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.

  • This doesn't work if the RDP window is minimized
    – andrew
    Jul 23, 2021 at 13:12
  • It does, as you can run it from inside the RDP target.
    – Overmind
    Jul 27, 2021 at 7:18
  • doesn't work for me inside a minimized remote desktop session. windows 10 enterprise build 18363
    – andrew
    Aug 2, 2021 at 7:50

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 this comment. It's a simple AutoHotkey script which you run on your remote machine.

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

 DllCall( "SetThreadExecutionState", UInt,0x80000003 )
  • doesn't work in my case.
    – tinker
    Oct 5, 2021 at 11:44
  • To be clear, the script should be run on the remote machine, not the machine running Remote Desktop. Edited my post now. Actually, I run it on both machines as it solves the same policy problem on my local desktop too. Oct 6, 2021 at 6:53

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

  • I was optimistic about this, but it didn't work for me. I tried it first on the remote PC - didn't work. Then I ran it on my local PC. Seemed to work for awhile, but after a few hours, I got the RDP disconnect message, as in my original post. Any ideas? May 4, 2020 at 23:32
  • I'll try keepalive next. Is this supposed to be run inside the remote RDP session PC? Or on my local PC? May 4, 2020 at 23:33
  • keepalive is alo meant to be run on your local machine. But frankly i would be surprised if keepalive works when ImAlive doesn't. keepalive is in a very early stage...
    – sapisch
    May 5, 2020 at 14:01
  • I looked at keepalive - all it does is press scroll lock every 5 minutes. I'm very doubtful of this since neither caffeine nor mousejiggler worked. It's surprising that there are no solutions that actually work. All that is needed is for the local machine to send a keystroke or mouse movement into the RDP session, and it stays alive. How can that be so hard? May 5, 2020 at 15:07

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

  • Is this done on local or RDP remote? May 8, 2020 at 13:06
  • That's on the machine you're RDP'ing to, the path to the local group policy RDP session time limits setting, if it's not configured then your admins have set it in the domain GP which you won't see, unless perhaps you can install RSAT in order to view your domain policies to see what the time limit value is set to by your domain admin(s) May 8, 2020 at 13:39

I use RDP Session Keep Alive:



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.


Put an analog watch under your mouse. The mouse will see the second hand moving and not go to sleep

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.