Disconnecting Remote Desktop sessions

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:

qwinsta /server:MainDbSrv

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.

You should never kill another user’s session without contacting them first – no matter how urgently you need to be able to connect to the server in question. It may be that the connection is performing a long-running update or script which could prove catastrophic if interrupted.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: