To prevent RDP (Remote Desktop Protocol) sessions from disconnecting when your Mac locks or goes to sleep while using the WindowsApps application (a Microsoft Remote Desktop client on macOS), you need to adjust settings both on your macOS system and on the Windows host to keep the session alive during lock or sleep events.
Here’s a detailed breakdown of how to configure your setup:
1. Prevent macOS from Sleeping or Locking
By default, macOS might put your system to sleep or lock the screen after inactivity, which can cause RDP sessions to disconnect. To prevent this:
Adjust Energy Settings:
- Open System Settings (or System Preferences depending on macOS version).
- Go to Battery (or Energy Saver).
- For Battery and Power Adapter tabs:
- Set Turn display off after to Never (or a long duration).
- Disable "Put hard disks to sleep when possible".
- Disable "Enable Power Nap".
- Prevent sleeping when connected:
- Toggle Prevent computer from sleeping automatically when the display is off (for desktops).
- Also, you can use the
caffeinate command in Terminal to keep macOS awake:
caffeinate -di
- This will keep display and system active indefinitely until the command is stopped (Ctrl+C).
2. Configure Windows Host for Session Persistence
Even if your Mac stays awake, the RDP session can still disconnect if the remote Windows system logs out, times out, or drops the session on screen lock.
Adjust Group Policy on the Windows Host:
If you're connecting to a Windows Pro/Enterprise system:
- On the Windows machine, open Group Policy Editor (
gpedit.msc).
- Navigate to:
Computer Configuration > Administrative Templates > Windows Components > Remote Desktop Services > Remote Desktop Session Host > Session Time Limits
- Configure the following settings:
- Set time limit for active but idle Remote Desktop Services sessions: Disabled or set to a high number.
- Set time limit for disconnected sessions: Never (or set to desired duration).
- End session when time limits are reached: Disabled.
Note: A screen lock (Win+L) shouldn’t log you off, but some environments have policies that do. The above settings help.
Registry Alternative (if no Group Policy):
Open regedit and navigate to:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\
- Add or modify
KeepAliveEnable as DWORD value to 1.
Then go to:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp
- Add or modify:
MaxIdleTime = 0 (DWORD, in milliseconds; 0 means never).
KeepAliveTimeout = value in ms (e.g. 60000 for 1 minute).
fKeepAliveTimeout = 1.
Reboot or restart the RDP service after making changes.
3. Use Microsoft's Official Remote Desktop App (WindowsApps)
Your WindowsApps RDP tool is likely referring to Microsoft Remote Desktop from the Mac App Store.
To ensure it's maintained:
- Use the latest version from the Mac App Store.
- In the app:
- Open your saved RDP session settings.
- Enable "Reconnect if connection is dropped" (found in advanced connection settings).
- Try enabling Device redirection (clipboard or printer) to keep an active session “heartbeat."
4. Optional: Use Dynamic Keep-Alive Script (on Mac)
To send regular network pings and prevent RDP timeout:
while true; do ping -c 1 <remote-rdp-host-ip> > /dev/null; sleep 60; done
This simple keep-alive can help in some NAT / firewall scenarios.
Summary
| Component | Setting |
|---|
| macOS (local) | Prevent sleep / lock, use caffeinate if needed |
| Windows (remote) | Adjust RDP timeout group policies / registry |
| Microsoft RDP App | Enable "Reconnect if disconnected" |
| Network (optional) | Use pings/heartbeat to avoid idle router dropping |
Let me know if you need help with a script or automating these settings!