Hello,
I have Windows Server 2022 on Azure. I log into that server via the remote desktop manager, but if I do not log in before the period, the user account gets logged out after 24 hours. Once I log in, it will take that as a reference time for the next logout session after 24 hours.
For example, let's say I log in today at 9 AM and do my work and just close the remote desktop leaving the user account logged in, so after the next day the user account will be signed out at 9 AM if I did not log in before that. And considering that I log in before let's say at 2 am, then it will sign out on the next day at 2 am.
The reason I want to keep the user account all the time is that there are a lot of jobs that are scheduled to run during the day.
I have tried editing the group policy, and registry, also it is not about no moment or live action on the server, because I am using a mouse giggler on it. Probably it is more about some setting for remote connection. I would appreciate it if someone could chime over here.
To prevent your Windows Server 2022 user account from being logged out after 24 hours on Azure, you need to address session timeout policies and settings that are likely causing this behavior.
The behavior you are experiencing is likely due to session timeout policies configured either at the operating system level or within Azure’s environment. These policies are designed to log off inactive or idle sessions for security and resource management purposes. However, in your case, it seems tied to a specific time period (24 hours) rather than inactivity.
Modify Local Group Policy Settings
Press Win + R, type gpedit.msc, and press Enter.
Navigate to the following path: Computer Configuration > Administrative Templates > Windows Components > Remote Desktop Services > Remote Desktop Session Host > Session Time Limits
Adjust the following settings:
- Set time limit for active but idle Remote Desktop Services sessions: Set this to “Disabled” or configure it with a longer duration (e.g., 7 days).
- Set time limit for disconnected sessions: Set this to “Never”.
- End session when time limits are reached: Set this to “Disabled”.
Apply the changes by clicking OK and then close the Group Policy Editor.
Force a policy update by running the following command in an elevated Command Prompt: gpupdate /force
Restart your server or log off and back in for changes to take effect.
Check Registry Settings
If Group Policy changes do not resolve the issue, verify and modify registry keys related to session limits:
Steps
- Open the Registry Editor (
regedit
):- Press
Win + R
, typeregedit
, and press Enter.
- Press
- Navigate to the following key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server
- Look for these values (create them if they don’t exist) and set them as follows:
- IdleTimeout: Set this DWORD value to
0
(disables idle timeout).Path: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server Value Name: IdleTimeout Value Type: REG_DWORD Value Data: 0
- MaxDisconnectionTime: Set this DWORD value to
0
(prevents disconnection due to inactivity).Path: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server Value Name: MaxDisconnectionTime Value Type: REG_DWORD Value Data: 0
- IdleTimeout: Set this DWORD value to
- Restart your server after making these changes.
Verify Azure-Specific Timeout Policies
Azure environments may impose additional restrictions on session durations through its platform-level configurations:
Steps
- Log into your Azure portal.
- Check if there are any policies applied at the subscription or resource group level that enforce session timeouts.
- Specifically review settings under:
- Azure Virtual Machine Scale Sets.
- Azure Bastion Host (if used).
- If applicable, adjust these policies or consult with your Azure administrator.
Disable Automatic Logout via Task Scheduler
If none of the above resolves your issue, you can create a task in Task Scheduler that prevents automatic logout by periodically resetting session timers:
Steps:
- Open Task Scheduler (
taskschd.msc
). - Create a new task with these configurations:
- Trigger: Every hour (or less frequent depending on preference).
- Action: Run a simple script like moving the mouse cursor slightly or sending a keystroke using PowerShell.
- Example PowerShell script for keeping sessions alive:
Add-Type -TypeDefinition @" using System; using System.Runtime.InteropServices; public class MouseMover { [DllImport("user32.dll")] public static extern bool SetCursorPos(int X, int Y); } "@ [MouseMover]::SetCursorPos(100,100) Start-Sleep -Seconds 5 [MouseMover]::SetCursorPos(200,200)