Windows 2000 and later include two command-line tools called qwinsta and rwinsta that can query and reset a session on a remote machine. This can be extremely useful if you desperately need to connect to a server via Terminal Services (otherwise known as Remote Desktop or RDP) but receive a message stating that the maximum number of connections has already been reached.
For example, let’s say that I can’t gain access to the server MainDbSrv using Terminal Services because both sessions are used up. Provided I have an account with administrative rights on the remote machine I can use qwinsta to check the details of the currently connected services like so:
This will display something like this:
C:> qwinsta /server:MainDbSrv SESSIONNAME USERNAME ID STATE TYPE DEVICE console 0 Conn wdcon rdp-tcp 65536 Listen rdpwd rdp-tcp#470 Bob 1 Active rdpwd rdp-tcp#471 Jane 3 Active rdpwd
Now I know that Bob and Jane are the two people currently connected to the remote server. Since Jane left the office 20 minutes ago I might assume that she forgot to log off. I don’t know where Bob is but I only need one session so I’ll ignore him for now.
To disconnect Jane’s session I could then do the following:
rwinsta /server:MainDbSrv 3
Where 3 is the session ID returned in the output from qwinsta above.