How to Prevent Disconnected RDP Sessions from Logging Off in Windows Server 2008 R2


2 views

Many Windows Server administrators face a frustrating scenario: when an RDP session gets disconnected (whether due to network issues or manual disconnection), the server automatically logs off the session after a period. This behavior can interrupt long-running processes and cause applications to freeze or fail.

Windows Server 2008 R2 has built-in Group Policy settings that control session behavior. The key settings we need to modify are:

1. Set time limit for disconnected sessions
2. Set time limit for active but idle sessions
3. End session when time limits are reached

Here's how to configure these settings through the Local Group Policy Editor:

1. Press Win+R, type gpedit.msc and hit Enter

2. Navigate to:

Computer Configuration
  -> Administrative Templates
    -> Windows Components
      -> Remote Desktop Services
        -> Remote Desktop Session Host
          -> Session Time Limits

Set these specific policies:

- "Set time limit for disconnected sessions" → Enabled → "Never"
- "End session when time limits are reached" → Disabled
- "Set time limit for active but idle Remote Desktop Services sessions" → Disabled

If Group Policy isn't available, you can modify these settings directly in the registry:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services]
"MaxDisconnectionTime"=dword:0
"MaxIdleTime"=dword:0
"fResetBroken"=dword:0

After making changes, verify they're applied by running:

gpupdate /force

Then check the effective settings with:

gpresult /h report.html

If changes don't take effect:

  • Check for conflicting domain Group Policies
  • Ensure you're editing the Computer Configuration section
  • Restart the server if necessary

While keeping sessions active is convenient, consider these security implications:

  • Implement strong password policies
  • Set appropriate screen lock timeouts
  • Monitor active sessions regularly

As a developer working with Windows Server 2008 R2 VPS instances, I've frequently encountered the frustration of disconnected Remote Desktop sessions getting automatically logged off. This behavior becomes particularly problematic when running long-term processes or applications that can't handle sudden session termination.

Windows Server environments are configured by default to terminate disconnected sessions after a set period. This security-conscious behavior often interferes with development workflows where we need to:

  • Maintain application state across disconnections
  • Keep background processes running
  • Preserve debug sessions during network interruptions

Here's the most reliable method I've found through extensive testing:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services]
"fResetBroken"=dword:00000000
"fDisableAutoReconnect"=dword:00000000
"KeepAliveEnable"=dword:00000001
"KeepAliveInterval"=dword:00000001
"MaxDisconnectionTime"=dword:00000000
"MaxIdleTime"=dword:00000000

To implement this:

  1. Open Registry Editor (regedit.exe)
  2. Navigate to the specified path
  3. Create these DWORD values if they don't exist
  4. Set all values as shown above
  5. Reboot the server for changes to take effect

For environments where Group Policy is preferred:

gpedit.msc → Computer Configuration → Administrative Templates → 
Windows Components → Remote Desktop Services → Remote Desktop Session Host → Session Time Limits

Configure these settings:

  • Set "Set time limit for disconnected sessions" to "Never"
  • Configure "Set time limit for active but idle sessions" as needed
  • Enable "Keep Alive" connection settings

For scripted deployment across multiple servers:

# Disable automatic logoff for disconnected sessions
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services" 
    -Name "MaxDisconnectionTime" -Value 0 -Type DWORD

# Enable session persistence
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server" 
    -Name "KeepAliveEnable" -Value 1 -Type DWORD
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server" 
    -Name "KeepAliveInterval" -Value 1 -Type DWORD

# Disable broken session reset
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services" 
    -Name "fResetBroken" -Value 0 -Type DWORD

After implementing these changes:

  • Test by disconnecting from an active RDP session (don't log off)
  • Wait 5-10 minutes and reconnect to verify session persistence
  • Check Event Viewer for Terminal Services-related errors if issues persist

Remember that these settings may need to be reapplied after Windows Updates, as some updates reset terminal services configurations.