ArtinSoft's Blogs

Software Migration Experts
Welcome to ArtinSoft's Blogs Sign in | Join | Help
in Search

Jose Aguilar's Blog

All things migrations, software and technology

Killing open Terminal Services sessions remotely

This tip isn't really migration-related, but I've used it so many times these past few days that I think it is worth sharing. We work with virtual machines A LOT, using Virtual Server 2005 R2 SP1. Every once in a while you need to log into a server using Terminal Services to delete old VHDs to make room for a new one, opr just for any other miscelaneous task that can't be done through the web administration client. And, unfortunately, sometimes there are two terminal services sessions open already, so you get the following error:

"Terminal server has exceeded maximum number of allowed connection"

You then stare at your monitor in frustration for a few seconds. After that, you figure out who the culprit is and ask him politely to "PLEASE LOG OFF".

Well, after discovering this tip, there is no longer a need to stare at your monitor or to ruin your relationship with your coworkers. Turns out there are a couple of command line tools you can use to close remote Terminal Services sessions. They are available in both Windows XP and 2003. The first one, qwinsta, lists all the open sessions on a particular server:

 c:\>qwinsta /server:192.168.123.123
 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
 console                                     0  Conn    wdcon
 rdp-tcp                                 65536  Listen  rdpwd
                   jpena                     1  Disc    rdpwd
                   administrator             3  Disc    rdpwd

In this case, you can see that Juan Peña (user jpena) has an open session in the disconnected state. In order to close his session, you need to use the second tool, rwinsta:

rwinsta /server:12.12.12.12 3

This command will kill the session with ID 3 (jpena's). And voilà! After this, I'm able to connect to the server. :-)

Credit goes to Scott Forsyth's WebLog.

Published Feb 29 2008, 05:22 PM by Jaguilar
Filed under:

Comments

 

Christian Saborío said:

Nice hint!

I think you can accomplish the same by using the /console switch if you invoke terminal services through the command line:

mstsc -v:servername -console

You will be able to access the session 0 console and kick anyone off once you are logged on.

February 29, 2008 7:11 PM
 

Mrojas said:

Thanks Chepe!!! This is the tip I was really, really, really looking for!!

March 4, 2008 2:47 PM
 

ahmed said:

thanks very much

April 7, 2008 3:17 PM

Leave a Comment

(required) 
(optional)
(required) 
Submit
Powered by Community Server (Non-Commercial Edition), by Telligent Systems