How to keep an RDP session alive?
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.
I have tried the following, without success:
- How do I keep an RDP session alive from the client side?
- https://honeywellaidc.force.com/supportppr/s/article/How-to-prevent-RDP-connections-from-disconnecting
- https://stackoverflow.com/questions/5528412/keeping-remote-desktop-session-alive
- https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/query-session
- https://serverfault.com/questions/758930/how-can-i-view-active-remote-connections-rdp-to-a-windows- - server
- caffeine.exe (both on my local PC and on the remote PC at the same time)
- mousejiggler.exe (both on my local PC and on the remote PC at the same time)
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
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
.
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.