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.

WindowssessionadmincliMedium risk
Run query session to find the ID, then logoff <id> (add /SERVER:hostname for a remote machine).

01Command

Command
$ query session ; logoff 3 /SERVER:fileserver01

02What 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

RiskMedium risk
RequirementsLogging off other sessions requires admin rights on the target machine; Remote Desktop Services role needed for remote /SERVER use
!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)
    Microsoft Learn · vendor-doc · 2026-09-17
    Evidence: Documents logoff syntax: session name or ID, plus /SERVER to log a user off a remote host.
  • query session (Windows Commands)
    Microsoft Learn · vendor-doc · 2026-09-17
    Evidence: Documents query session, which lists session names and IDs that logoff requires as arguments.

Last verified: 2026-09-17 · Category: Security & Privacy