用 logoff.exe 注销用户会话
系统内置的 logoff 命令按会话 ID 结束会话——清理服务器上卡住的断开 RDP 会话的标准做法。
先运行 query session 找到会话 ID,再执行 logoff <id>(远程机器加 /SERVER:主机名)。
01命令
命令
$ query session ; logoff 3 /SERVER:fileserver0102作用说明
服务器上的断开 RDP 会话会不断累积直到达到连接数上限,logoff 是无需图形工具即可清理它们的轻量方式。注销会话会终止其中的所有进程,该会话中未保存的工作会丢失,所以务必先用 query session 确认 ID。不带参数运行 logoff 会注销当前自己的会话,在脚本里非常实用。
03风险
!注意: 注销会话会终止其中的所有进程,未保存的工作将丢失。
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- logoff (Windows Commands)依据: Documents logoff syntax: session name or ID, plus /SERVER to log a user off a remote host.
- query session (Windows Commands)依据: Documents query session, which lists session names and IDs that logoff requires as arguments.
最后验证: 2026-09-17 · 分类: 安全与隐私