I would like to log off a specific local user using the command line in windows 8. How can this be done?
2 Answers
Use QUERY USER to get a list of logged on user sessions. Then use LOGOFF # (replacing # with the appropriate session ID seen in the previous command's output) to log off the user.
There might be a slightly more graceful way to do it in one line with PowerShell, but this should work all the way down to XP regardless. If UAC is enabled, you will need to run these commands from an elevated prompt.
4As OP found, quser isn't included in Home editions of Windows. But you can use the Cassia project which has similar functionality.
If you unzip the release and run:
Samples\SessionInfo\Source\SessionInfo\bin\Release\SessionInfo.exe listsessions $env:COMPUTERNAME the output will include Session IDs and Users. Get the session ID for the user, then run as admin:
Samples\SessionInfo\Source\SessionInfo\bin\Release\SessionInfo.exe logoff $env:COMPUTERNAME 3I wanted to automate this, so I wrote a small program using Cassia that loops through all sessions and signs off all other users.