Howto: Remotely disconnect a Terminal Services Session

by admin on April 9, 2008

[update 2008-08-06]
I’ve written about another method for remotely disconnecting a terminal server session can be found here.

Windows server 2000/2003 allows two remote terminal services connections for administrative purposes.  Every once in a while I’ll get the “You exceeded the allowed connection count” message when trying to connect to a server via RDP, because previous sessions were not disconnected correctly.

You can use either of the following methods to remotely disconnect Terminal Server sessions.

Method 1

You can normally run the Terminal Services Manager program on another server, or even from a Windows XP workstation, to disconnect Terminal Services connections by clicking StartRun and then typing

%SystemRoot%\system32\tsadmin.exe

This will launch the local copy of Terminal Services Manager.  Next right click on All Listed Servers and select Connect to Computer.  Type in the name or IP address of the server you wish to manage. 

 All Listed Servers in Terminal Services Manager

Select your server from the left pane, then select the Sessions tab from the right pane.  Right click on the session you wish to disconnect and select Disconnect.

You should now be able to login to the target server via Terminal Services.

Method 2

Authenticate to the server you wish to manage.  You can easily accomplish this by mapping a network drive to a share on the target server.  Start a command prompt and type

qwinsta /server:yourservername

where yourservername is the name or IP address of the server you wish to manage.

In my case I ran qwinsta /server:10.0.0.2

You can see the Administrator account is logged into session 0 and the admin account is logged into session 1.  To disconnect the admin session with ID=1 I’ll run the following from a command prompt:

rwinsta ID /server:yourservername

where ID is the process ID of the sesstion you wish to terminate, and yourservername is the name or IP address of the server you wish to manage.

In my case I ran rwinsta 1 /server:10.0.0.2

I again ran qwinsta /server:10.0.0.2 which verified session 1 had been disconnected.  I confirmed that I was once again able to login to Terminal Services.

Thanks to Ingo for some of the information, which I found via Andy.

Related Posts

{ 13 comments… read them below or add one }

Anthony Brown April 15, 2008 at 12:24 am

Very detailed and helpful article. Most articles of a technical nature leave out steps, thanks for being concise.

Reply

Rich April 18, 2008 at 8:27 pm

Love the command-line trick. Very cool.

Another way to deal with “too many users connected” is to use the console to connect.

mstsc /v:targethost /console

We had a policy at a few shops I’ve worked at that, on production servers, admins only connect to the console session.

Reply

bamba July 24, 2008 at 7:26 am

In Windows Vista and 2008 there is a newer version of mstsc which hasn’t /console parameter anymore. You have to use /admin parameter instead:
mstsc.exe /v:servername /admin

Reply

Joel Maust September 11, 2008 at 9:57 am

Thanks for the tip; very helpful.

One note, though, is that you first spell “rwinsta” without the “n”. And that caused the command to not work until I figured out that it was supposed to have the “n” in it.

You spell it right the second time, so it’s not a big deal and I’m sure people figure it out… just thought I’d point it out.

Thanks again.

Reply

Julie September 11, 2008 at 12:34 pm

Thanks for pointing that out Joel. I’ve fixed the problem.

-Julie

Reply

Brian January 19, 2009 at 9:15 am

Nothing constructive to add but I just wanted to say thanks, I have tried for ages to find something like this and this is the best article by far.

Thank you!

Reply

Jon February 26, 2009 at 5:41 am

Thanks @ Bamba ; the /admin change threw me after a force rollout of the new ts client at work!

Whhhyyyy will me /console command not work??? *shakes fist* All fixed now

Reply

Ramesh April 14, 2009 at 7:24 am

Great Solution. Thanks for detailed instructions.

Reply

DISTURBED690 July 7, 2009 at 6:43 pm

Great knowledge share! Thanks a lot!

Reply

Mohammad August 29, 2009 at 8:30 pm

Cool ! Big Thanks

Reply

Rob Weinstein November 27, 2009 at 12:28 pm

Thanks a lot. Ran into this a bunch of times and didn’t know how to fix it remotely and never bothered to look it up until today.

Reply

Young K March 23, 2010 at 1:27 am

Thanks. I run into this every now and than, and I keep forgetting the commands.

Reply

Yaarik November 3, 2010 at 3:46 am

This is a lifesaver on Windows 7 where I don’t have tsadmin.exe.

Thank You!

Reply

Leave a Comment

{ 1 trackback }

Previous post:

Next post: