Remotely disconnect remote desktop / terminal services users

Shaun Ewing Popular, Technology 14 Comments

We have a reasonable number of Windows servers, and from time to time people forget to log off resulting in that dreaded message “The terminal server has exceeded the maximum number of allowed connections.”:

In an environment where one server might be used by a small team during business hours, you can usually around until you find the culprit but this isn’t always possible and you sometimes need to resort to other methods to access the server.

The easiest way to get access is to use another recent version of Windows to disconnect inactive users using two commands ‘qwinsta’ and ‘rwinsta’. You will need to have administrator rights on the remote machine to do this.

First of all, let’s get a list of users. Access a command prompt and enter the command “qwinsta /server:remoteipaddress” for example:

You may receive an access denied message like the following:

If you get the above error message, you will need to authenticate to the remote system. The easiest way to do this is to access a share (eg: C$) as Administrator.

If you successfully authenticated, you should receive output like the following:

You can see that there are two remote desktop sessions active, one as “Administrator” (which is disconnected) and another as “s.ewing”.

The connection for “Administrator” is a good candidate for disconnection, because it’s currently inactive. Let’s disconnect that one.

To disconnect a user, all you need is the “ID” from above. In this case, it’s “1”.

From the command prompt again, you’ll need to enter the following at the command prompt “rwinsta /server:remoteipaddress id”, for example:

The command won’t display any output if successful, but let’s query the server again to see if it worked:

You can see that there is no longer a session for ‘Administrator’ and therefore the session was successfully disconnected.

Enjoy!

About the Author
Remotely disconnect remote desktop / terminal services users was last modified: April 20th, 2017 by Shaun Ewing

Comments 14

  1. 1st, you are not "disconnecting" the session. You are logging them off. Disconnected sessions show up as being as disconnected which means the Terminal Server or XenApp server lost the connection with the client and is waiting for the client to reconnect. When they do, they resume where they left off- losing no work.

    What you are doing is the equivalent of logoff [session #] /server:[the server name] from a Command Prompt. The session is logged off.

    Very different results. I’m posting this because tech folks without experience may not recognize the differences.

    1. Indeed. I was looking to disconnect a session, like what happens when someone logs in locally at a client workstation and the remote session gets booted. This performs a logoff, and I need to be able to boot a user from a session and not lose what they have open.

  2. Holla there,

    I would like to know how to disconnect the account that "Listen"-ing. Because as long as there is one that "Listen", whenever i try to remote, i will be directed to a fresh session.

    1. Hi fh,

      It seems this information was lost during a site migration. I’ve fixed it up. Thanks for the report!

      -Shaun

  3. Thank you very much. This worked great and I found that I had a total of 3 stale disconnected administrator logins. Removed them using the ID code and now im in! Saved me a trip.

Leave a Reply

Your email address will not be published. Required fields are marked *