When you disconnect from a Remote Desktop Protocol (RDP) session to a Windows 7 machine, the system defaults to logging out the user session. This occurs because of how Terminal Services handles disconnected sessions in Windows 7.
The most reliable method involves modifying the Windows Registry:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services]
"fDisableForcibleLogoff"=dword:00000001
"MaxDisconnectionTime"=dword:00000000
"MaxIdleTime"=dword:00000000
Create a .reg file with this content and merge it into the registry, then restart the terminal services:
net stop termservice
net start termservice
For domain environments, configure these settings via Group Policy:
- Open
gpedit.msc
- Navigate to: Computer Configuration → Administrative Templates → Windows Components → Remote Desktop Services → Remote Desktop Session Host → Session Time Limits
- Set "Set time limit for disconnected sessions" to "Never"
- Set "End session when time limits are reached" to "Disabled"
For automated deployment across multiple machines:
# Configure RDP session persistence
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services" -Name "fDisableForcibleLogoff" -Value 1 -Type DWord
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services" -Name "MaxDisconnectionTime" -Value 0 -Type DWord
Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services" -Name "MaxIdleTime" -Value 0 -Type DWord
# Restart Terminal Services
Restart-Service -Name TermService -Force
- Security implications of persistent sessions
- Resource consumption on the remote host
- Compatibility with Windows 7 SP1 and later updates
If changes don't take effect:
- Verify UAC isn't blocking registry changes
- Check for conflicting Group Policy settings
- Confirm proper permissions on registry keys
When you disconnect from a Remote Desktop Protocol (RDP) session to a Windows 7 machine, the system automatically logs out the user by default. This behavior can be problematic when you need to:
- Run long-running processes that continue after disconnection
- Maintain application state for the next connection
- Allow multiple users to share the same session
Windows 7 provides several ways to modify this behavior through Group Policy and registry settings. Here's the most reliable method:
Method 1: Using Group Policy Editor
1. Press Win+R, type gpedit.msc
and press Enter
2. Navigate to:
Computer Configuration → Administrative Templates → Windows Components → Remote Desktop Services → Remote Desktop Session Host → Session Time Limits
3. Double-click "Set time limit for disconnected sessions"
4. Select "Enabled" and set "End a disconnected session" to "Never"
5. Click Apply and OK
Method 2: Registry Modification
For systems without Group Policy Editor (like Windows 7 Home), use this registry tweak:
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services] "fResetBroken"=dword:00000000 "MaxDisconnectionTime"=dword:00000000 "MaxIdleTime"=dword:00000000
Save this as keep_session.reg
and double-click to merge into registry.
You can also configure this via command line using tscon
and query session
:
@echo off for /f "skip=1 tokens=3" %%s in ('query session ^| find "Active"') do ( tscon %%s /dest:console )
This script will move your RDP session to console when disconnecting.
After making these changes, test the configuration:
- Connect via RDP
- Open Command Prompt and run
query session
- Note your session ID
- Disconnect (don't log off)
- Wait 1 minute and reconnect
- Run
query session
again - your session should still be active
While this solution works, be aware of these implications:
- Security: Anyone with physical access can resume your session
- Resource usage: Disconnected sessions still consume memory
- Multiple sessions: Windows 7 only supports one active session at a time
If the settings don't take effect:
- Ensure you're editing the correct policy (Computer vs User configuration)
- Run
gpupdate /force
after Group Policy changes - Check for conflicting settings in other policies
- Reboot the machine if changes don't appear immediately