If you use Windows Terminal Services for remote desktop access, it’s common to run into this nasty error message from time to time:
The terminal server has exceeded the maximum number of allowed connections.
The error refers to the maximum 2 remote connections that are allowed to a Windows 2000 server (or up… XP only allows 1). Now, only a crazy person would ever consider connecting more than one or two users remotely to a server, and even though that would never, ever, even in a million years, need to happen, that error still crops up from time to time.
The problem is that if a user closes their terminal services client without logging out, their remote session switches to “disconnected” mode and will continue using up one of those two available connections.
While I’m sure we all agree that this is an awesome feature, sometimes in an emergency you need to log into a server and all of its connections are already in use. There are a couple of really useful and mostly unknown command line utilities that will allow you to remotely find and kill other remote desktop sessions, whether they are in a connected or disconnected state.
On most systems, these tools are qwinsta.exe and rwinsta.exe, though on some 2003 systems these appear to have been renamed and might be available as query.exe and reset.exe, respectively. Use whichever is available on your machine.
Finding disconnected sessions with qwinsta or query
Run “qwinsta /server:theserver_or_ip” or “query session /server:theserver_or_ip”, using the server name or ip address of the machine you can’t log in to. You’ll get something like the following:
SESSIONNAME USERNAME ID STATE TYPE DEVICE console 0 Conn wdcon rdp-tcp 65536 Listen rdpwd rdp-tcp#5 auser 1 Active rdpwd rdp-tcp#7 another 2 Disc rdpwd
From this, you can see that users “auser” and “another” are using the two remote Terminal Services connections. Furthermore, the remote desktop client that “auser” is using is still connected to the server, whereas “another” is in a disconnected state, probably the result of closing the remote desktop window instead of logging off.
Killing disconnected sessions with rwinsta or reset
Run “rwinsta sessionid /server:theserver_or_ip” or “reset session sessionid /server:theserver_or_ip”, using the session id obtained above (1 for “auser” and 2 for “another”) and the name or ip address of the server. In this case, you’d probably want to kill session 2, since that user is disconnected anyway.
The command will run without a response, but if you run qwinsta (or query) again, you’ll notice that the session is no longer there. More importantly, if you try and connect to the machine using remote desktop, you’ll get in.
18 thoughts on “HOWTO – kill terminal services sessions remotely”
Comments are closed.
great post. i used to run into this all the time at my old job (where i was an accidental admin). the users would unknowingly leave themselves logged in, and i was always sending them an explanation of the difference between “disconnecting the session” and actually logging off. wish i had known this stuff at the time … might’ve saved some aggravation!
Alternatively, you can log in to the console session via RDP by adding /console after the IP address in the connect field.
Most certainly a handy trick, and the sarcasm is thoroughly appreciated!
See MS support artciles on MSTSC switches and use of Mstsc.exe with the CONSOLE switch.
your post helped me to get my remote deskotp working again.
Before I was able to execute the qwinsta or rwinsta on a remote server, I had to authenticate to the server using net use, for example: ‘net use \ /USER:() “”‘, example: net use \192.168.1.1 /USER:administrator “password”
maybe this can help some other users too ;)
I have written a GUI that does this for you if anyone is interested. It allows you to query a server by name or IP and kill a specified user. It can be found at: http://www.jonathanrhodes.net/
this has sorted out my biggest problems of having to call up people to check who is logged in!!! Thanks a lot.
Thank you very usefull info buddy.. Keep posted
Thanks,
Ganesan
Try this best resolution i found:
We’ve had the same issue and have found a different way to resolve the issue which doesn’t require a server reboot.
Start Remote Desktop Services Manager
Identify the user ID in the Users tab
In the Processes tab sort by ID
Go down to the user ID and end the winlogon.exe process
the user session will be logged off
A server reboot will probably be beneficial at the end of the day