Event ID 40: Session was disconnected with reason code
Written on the destination when a session disconnects, recording the session ID and a numeric reason code for the disconnect.
- Channel
- Microsoft-Windows-TerminalServices-LocalSessionManager/Operational
- Logged by default
- Yes
- Written on
- Target host
- Volume
- Moderate
- Provider
- Microsoft-Windows-TerminalServices-LocalSessionManager
- Needs a SACL
- No
Key fields
Exact XML field names, as they appear in <Data Name="…"> and in SIEM field extractions.
| Field | What it tells you |
|---|---|
| Session | Session ID that was disconnected |
| Reason | Numeric disconnect reason code (e.g. 0 = no additional information, 5 = server-initiated, 11 = user-initiated via the Disconnect button). Microsoft does not publish a full table, so treat high or unusual codes as context, not a verdict |
Analyst notes
- 0140 is written for essentially every disconnect, so it is high-noise; use it to time disconnects and pair it with 24/25 rather than alerting on it alone.
- 02Reason codes are only partly documented publicly. Common ones: 0 (no info), 5 (disconnected by the server), 11 (user clicked Disconnect). Do not over-interpret rare large values.
Pull this event
Retrieval queries for a live host, a collected .evtx file and common SIEMs. Filter further on the key fields above.
Get-WinEvent -LogName 'Microsoft-Windows-TerminalServices-LocalSessionManager/Operational' -FilterXPath "*[System[(EventID=40)]]" -MaxEvents 50 |
Select-Object TimeCreated, Id, MachineName, Message-FilterXPath supports exact matches only. For substring matching, filter in Where-Object.
Where it shows up
Investigations, attack signals and lateral movement techniques that rely on this event.
ATT&CK mapping
Techniques this event can help detect. Most of these depend on specific field values; the event alone does not mean the technique happened.
Related events
Common questions
- What does Windows event ID 40 mean?
- Written on the destination when a session disconnects, recording the session ID and a numeric reason code for the disconnect. It is written to the TerminalServices LocalSessionManager log (Microsoft-Windows-TerminalServices-LocalSessionManager/Operational).
- Is event 40 logged by default?
- Yes, a default Windows installation records it.
- Where is event 40 recorded?
- In the Microsoft-Windows-TerminalServices-LocalSessionManager/Operational channel on the target host.
Decode a real event
Paste the XML and every value gets explained. Nothing leaves your browser.
Open decoderWritten on the destination when a session disconnects, recording the session ID and a numeric reason code for the disconnect. Key fields, logging requirements, ATT&CK mapping and ready-to-run queries.