How to force logoff a Windows user from the command line

Table of Contents

Case #

You need to locally or remotely logoff a Windows user but when clicking logoff/sign out from the task manager, the UI does not respond and nothing happens.

Solution #

You need to use the Windows terminal / CLI or Powershell to forcefully logoff a user. To force logoff a Windows user when being logged on locally on that machine, run the below commands on an elevated command prompt or Powershell window. The quser command output provides the user session ID, which you must use in the subsequent command to successfully logoff the stuck user.

quser
logoff [user session ID]

In the above example, there is only one user logged on at the moment, however in cases where there are other users stuck in disconnected state and you cannot log them off otherwise, the above commands can come in very handy. Also you can remotely logoff a user by using Powershell remoting or PsExec.

Powered by BetterDocs