Log Off a Session with logoff.exe
The built-in logoff command ends a session by ID — the standard fix for stuck disconnected RDP sessions on servers.
Run query session to find the ID, then logoff <id> (add /SERVER:hostname for a remote machine).
01Command
Command
$ query session ; logoff 3 /SERVER:fileserver0102What it does
Servers accumulate disconnected RDP sessions until they hit the license/connection limit, and logoff is the lightweight way to clear them without GUI tools. Logging off a session terminates all its processes — unsaved work in that session is lost — so confirm the ID with query session first. Without arguments, logoff ends your own current session, a handy shortcut for scripts.
03Risk
!Warning: Logging off a session kills all of its processes; unsaved work in that session is lost.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- logoff (Windows Commands)Evidence: Documents logoff syntax: session name or ID, plus /SERVER to log a user off a remote host.
- query session (Windows Commands)Evidence: Documents query session, which lists session names and IDs that logoff requires as arguments.
Last verified: 2026-09-17 · Category: Security & Privacy