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.

Note: This article assumes you’re running the command prompt as an administrative user who has access rights to the remote computer in question. (If you’re not sure how to do this, leave me a comment.)

Remotely List Users

To remotely list users, you need to use the quser command (short-form for the query user command) like so:

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:

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:

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.

Have any other tips? Leave a comment and let me know.