In RDP, how does disconnecting differ from logging off, and why is a closed session still there the next morning?
answer
- closing the window is not signing out
- the server refuses to shut down
- the wire ends, the session does not
- two audit events bracket it
basics
~20 sDisconnecting ends only the network connection; the session stays on the host with its programs running. Logging off ends the session. Closing the RDP client window is a disconnect, so the session remains until sign-out or a time limit.
solid answer
~40 sWhen a user closes the RDP client while logged on, the client may send a Shutdown Request, and the server **always denies it** with a Shutdown Request Denied PDU when a logged-on account is associated with the session. The client then sends an MCS Disconnect Provider Ultimatum and closes the connection, but the **session stays on the host**, so its processes keep running. Logging off ends the session on the server. The audit trail shows the disconnect as event 4779 and a later return as event 4778. To keep sessions from lingering, tell users to sign out, and set the session host's time limit for disconnected sessions so a forgotten one is ended after an interval you choose. A disconnected session is still a session with a logged-on account.
go deeper
Know that closing the window disconnects and leaves the session, and that signing out is what ends it.
Explain the Shutdown Request, the always-denied answer for a logged-on account, and that host state, not the wire, decides whether the session survives.
Use events 4779 and 4778 as evidence of disconnected sessions and set a time limit for disconnected sessions.
Decide how long a disconnected session may live for each population and make signing out part of the access agreement.
## Two different things A **disconnect** ends the client's connection to a session. A **logoff** ends the session. RDP sits on the first one: it is a connection protocol, and the session lives on the host. The wire can end while the session carries on, and that is exactly what happens when a user closes the client window. ## What the protocol does when a user closes the client MS-RDPBCGR section 1.3.1.4.1 describes two ways a client can handle the user closing the application: 1. Send an MCS Disconnect Provider Ultimatum PDU with the reason "user requested" and close the connection immediately. 2. Send a Shutdown Request PDU first and wait for the server's answer. The server's answer depends on whether a logged-on account is associated with the session. If one is, the server **always denies** the request and returns a Shutdown Request Denied PDU. The client then decides what to do; it might show a dialog saying the session will be disconnected, and if it proceeds it sends the Disconnect Provider Ultimatum and closes the connection. If no logged-on account is associated, the server closes the connection immediately after the request. The denial is the protocol's way of saying "you cannot shut down a logged-on session from here". The session remains. ## When the server ends it Sections 1.3.1.4.2 and 1.3.1.4.3 describe the server-side sequences: an optional Set Error Info PDU with a reason, an optional Deactivate All PDU, an optional MCS Disconnect Provider Ultimatum, and then the server closes the connection. They differ in the reason code: "user requested" when the user ends the session on the server, and "provider initiated" when an administrator forces a logoff or disconnects a session outside the user's control. At the protocol level a disconnect and a logoff therefore look alike: both end with the connection closing. What differs is host state, which RDP does not describe. ## What the host does On a session host the state is the session itself. - After a **disconnect**, the session and the programs in it keep running, and the user can reconnect to it. - After a **logoff**, the session ends and its programs are closed. - A session time limit on the host can end a disconnected session after an interval an administrator chooses, so that forgotten sessions do not accumulate. Microsoft's policy CSP page for Remote Desktop Services does not list that setting, so confirm the Group Policy or collection setting on your build. ## Coming back A disconnected session is resumed by connecting again with the same account: the existing Terminal Services session is reattached and event 4778 is generated, which its page describes as a user reconnecting to an existing session. Which of several hosts a returning user lands on in a farm is a broker question and is not covered here; this answer is about one host. ## What the audit trail shows Two Windows security events, both in the Audit Other Logon/Logoff Events subcategory, bracket this: - **4779**: "A session was disconnected from a Window Station". It is generated when a user disconnects from an existing Terminal Services session, and also for Fast User Switching and for the enhanced-session console of a virtual host. - **4778**: "A session was reconnected to a Window Station". It is generated when a user reconnects. Both carry Account Name, Account Domain, Logon ID, Session Name (for example `RDP-Tcp#3`), Client Name and Client Address. A 4779 followed days later by a 4778 for the same Logon ID is a session that sat disconnected. Neither event states that the user later signed out. ## Why this matters to a data-protection review A disconnected session keeps whatever the user had open, including documents from a redirected drive or content copied through the clipboard. A contractor who closes the window on Friday has not removed their work from the host, and the session is still a live, logged-on account until it is ended. - Teach users to sign out, not just close. - Set a time limit for disconnected sessions. - Monitor 4779 and 4778 for high-value accounts and for client addresses outside the expected list, as the event pages recommend. - Remember that a locked session is not a boundary either; see the material on automatic reconnection. ## Common mistakes - Believing closing the window logs the user off. - Believing the Shutdown Request PDU shuts the session down. - Reading event 4779 as a logoff. - Assuming a disconnected session has no running processes.
- A user's account shows event 4779 on Friday evening and event 4778 on Monday morning. What does that pair tell you and what does it not?It tells you the session was disconnected and later reattached, with the account, session name, client name and client address at each point. The gap is how long it sat disconnected. It does not tell you that anything was copied, that the same person was at the keyboard, or how the user was authenticated, because those are not fields of either event.
- Why can an administrator disconnecting a session look like a user disconnecting at the protocol level?Both server-side sequences use the same kinds of PDU: an optional Set Error Info, an optional Deactivate All and a Disconnect Provider Ultimatum, then the server closes the connection. The Ultimatum's reason code differs, user requested versus provider initiated. Whether the session survives is decided on the host, not by the PDUs.
Closing the client is like walking away from a desk with the lamp on and the papers out: you have left, but your work is still there until someone clears the desk.
- Says closing the RDP window logs the user off
- Believes the Shutdown Request PDU shuts down a logged-on session
- Reads event 4779 as proof the user logged off
- Assumes programs stop when the connection drops
- Assumes a disconnected session no longer has a logged-on account