If you’ve ever had to connect to a server via remote desktop and got a message stating “The Terminal Server has exceeded the maximum number of connections.” Then you know how I feel whenever I see this. It’s a pain because in order to log them off, you need to log in yourself. Or do you?
Fortunately, Windows has some built-in command line tools that will allow you, if you have administrative access, to remotely list and log users off of a remote server.
This apparently only works on the following versions of Windows: Windows 8, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, and Windows Vista. If you’re not connecting to one of those, you’ll have to try another way. There’s another option via remote desktop that allows you to log in to the console session, but I will cover that in another article.
Remotely List Users
To remotely list users, you need to use the quser command (short-form for the query user command) like so:
1 |
quser /SERVER:RemoteMachineName |
This code will list the users on the remote machine with the hostname RemoteMachineName (obviously, replace this with the remote computer name). The output looks something like this:
1 2 3 |
USERNAME SESSIONNAME ID STATE IDLE TIME LOGON TIME User1 1 Disc none 6/19/2014 7:15 PM User2 16 Disc none 7/29/2014 12:01 PM |
In the output above, the things we care about are:
- Username – is the username of the person logged into this session.
- ID – indicates the unique session ID.
- State – indicates the current state of the connection.
Remotely Log a User Off
Once you’ve found the user you want to log off, ensure their status is “Disc” (Disconnected). If it’s not, they may be doing something on the server, so you should probably give them a call and just ask them to log out.
If you still want to go ahead and log them out, just make a note of the session ID and run the following command:
1 |
logoff 16 /SERVER:RemoteMachineName. |
In this case, we’re logging off User2 with session ID 16. Replace the 16 in the command with the session ID you found from the quser command and, again, replace RemoteMachineName with the name of the server you’re trying to connect to remotely.
Done!
That’s it! If we run the quser command again, we can see that it worked.
1 2 3 4 |
>quser /SERVER:RemoteMachineName USERNAME SESSIONNAME ID STATE IDLE TIME LOGON TIME User1 1 Disc none 6/19/2014 7:15 PM |
Have any other tips? Leave a comment and let me know.
Frank says:
Very nice! Could always connect to the console session though and kick them off from there 🙂
Richard Marskell says:
Definitely. That’s the alternate method I mentioned. 😀
Arun says:
But if i have multiple session which are in desc state and i want to logoff once all multiple session with state desc
how to do this ?