Disconnect Open Terminal sessions remotely.

When you are trying to access the server, have you ever encountered "The terminal server has exceeded the maximum number of allowed connection" error?  or "The user is attempting to log on to a Terminal Server in Remote Administration mode, but the server has reached its connection limit. Terminal Servers in Remote Administration mode allow a maximum of 2 concurrent sessions, active or disconnected." This happens because of limited allowed connection or not enough licenses.

To get the connection, you have to disconnect the session.

If you have to access that server regularly and you often get that error, you can create a batch file which will disconnect the session and will allow you to log in.

Editor's note: this may be an indication that you are not properly logging off of sessions and simply clicking the "X" at the top of the terminal window, which disconnects and leaves session logged in, or, if you (and your organization) typically log off correctly, that someone is actively working on something and so disconnecting session forcefully could be harmful.  So please ensure you have a good understanding of your environment and which of these scenarios you are in.

Here's what you have to do.
(Assume that your server name that you are trying to connect is MyServer and the password for that server is MyPassword.)

Open a notepad, and type this:
net use /user:administrator \\MyServer\c$
                      reset session 1 /server:MyServer

Open in new window

Save as the file as DisconnectSession.bat and put that on your desktop.

When you encounter the issue, just double click that batch file and you are all set to go.

Alternatively, you can disconnect the session using Terminal Services Manager. If you are on a server, you can run tsadmin, Terminal Services Manager is available by default on servers; however, you can install the adminpak for Windows Server to get this functionality on workstations. If you want to run tsadmin from Windows XP workstation, then download the AdminPak.

Once available, here's what you do.

Click start | run...
type tsadmin and hit enter. (this will open the Terminal Server Manager)
Search for the computer you are trying to disconnect session for.  If you don't see the computer, click "Action | Connect to the computer" and provide the name of the computer or the IP address.
Click on the computer, on the right side you will see the users and the sessions, right click on the session (user name) and choose disconnect it.

Editor's note: again, based on your scenario/environment, the above option may be greyed out; therefore, you may need to choose "log off" or "reset".  Resetting of sessions should be done with great care though, so please refer here for more information.

This is very helpful when you have limited allowed connection and other admins or users frequently go to that computer. The best practice would be to check if the session is idle or not. Or, setup terminal server in such a way that if the session is idle for certain time, automatically disconnect the idle session.

Here's how to configure Terminal server that will disconnects the idle session automatically after a certain period of time.

Click on Start | Control Panel | Administrative tools
Click on Terminal Services Configuration
Click on the Connections folder, then, on the ride side, right click RDP-Tcp and select Properties
On the Sessions tab, check the Override user settings box and change the Idle Session Limit to any minutes or hours you want.  Additionally, check the button "Disconnect from session" when session limit is reached. (This way, if the session is idle for the amount of time you specified there, it will automatically disconnect the idle session.)

Comments (0)

Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.