Remotely disconnect remote desktop / terminal services users

July 12, 2009

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:

# qwinsta /server:10.1.2.3

You may receive an access denied message like the following:

Error 5 getting sessionnames
Error [5]:Access is denied.

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: