The Computer Oracle

How to keep an RDP session alive?

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Over a Mysterious Island

--

Chapters
00:00 How To Keep An Rdp Session Alive?
01:39 Accepted Answer Score 7
02:51 Answer 2 Score 4
03:20 Answer 3 Score 3
03:47 Answer 4 Score 2
04:11 Answer 5 Score 1
04:34 Thank you

--

Full question
https://superuser.com/questions/1547184/...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#windows10 #remotedesktop

#avk47



ACCEPTED ANSWER

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




ANSWER 2

Score 4


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.




ANSWER 3

Score 3


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
#Persistent
;in milliseconds - so 30000 would be every 30 seconds
SetTimer, NoSleep, 240000
Return
NoSleep:
DllCall( "SetThreadExecutionState", UInt,0x80000003 )
Return



ANSWER 4

Score 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




ANSWER 5

Score 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