If you work in IT, I’m sure you’ve run across a time that you needed to log off a user from a remote computers – even if it’s yourself (especially when it’s time to change your password). Personally, I have to change my network password every 30 days, and there are times that I may be logged into any of 150 computers. I try to remember to use the log off button, but sometimes, I have idle sessions on computers.
This being said, I needed a way to log off any session I was logged into, in a list of computers I knew I might be logged into. My first thought was to use PSLOGGEDON.exe (from Sysinternals) which is a fantastic tool, but I don’t want to search the entire domain, plus I might be logged in to multiple domains.
So, I found a nice little utility built right into windows – quser.exe
Quser.exe can be used to show what user is logged in to a remote computer, as well as the localhost. Use quser.exe /SERVER:servername to query a remote system.
If you want to specify just one user account instead of finding all users logged in, user this syntax: quser.exe user6 /SERVER:servername
Now to log off this user, or session, you can use another built-in utility in Windows – Logoff.exe
Logoff.exe can either log off a session ID, or SessionName remotely – not by username (username works locally though). The syntax is similar to quser.exe:
LOGOFF [sessionname | sessionid] [/SERVER:servername]
So to log off user6 from the example above, I can use either the session name (rdp-rcp#443 – or I can use the ID – 2 – I’ll go with the ID
logoff 2 /SERVER:server1
That was easy! Now, to check to see if I’m logged any of the 150 servers I manage, I create a quick bat file using excel (more on that here) and now I can run it at any time, and see what remote systems I’m logged into, and log my session off if needed.
This is a really simple way to do this, but if you have another way to do it, please post below! I’d love to see how you handle this problem!