HOWTO - kill terminal services sessions remotely

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.


Recent Entries

Comments

Oldest comments listed first.

Posted by: thousandrobots on August 15, 2007 at 11:44 PM

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!


Posted by: mr.sticky on August 18, 2007 at 7:08 PM

Alternatively, you can log in to the console session via RDP by adding /console after the IP address in the connect field.


Posted by: Motoma on August 20, 2007 at 12:51 PM

Most certainly a handy trick, and the sarcasm is thoroughly appreciated!


Posted by: menglis3 on August 21, 2007 at 3:06 AM

See MS support artciles on MSTSC switches and use of Mstsc.exe with the CONSOLE switch.


Posted by: VOODOOS!L on June 3, 2008 at 2:50 AM

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 ;)


Posted by: Jon on September 2, 2008 at 12:05 PM

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/


Posted by: Jonathan on January 22, 2009 at 11:36 PM

this has sorted out my biggest problems of having to call up people to check who is logged in!!! Thanks a lot.


Leave a comment


Subscribe to MAKE!Subscribe to MAKE Magazine!

Subscribe today, save 42% and get web access to MAKE free. MAKE Digital Edition is available only to subscribers.

$34.95 / 1 year
(4 Quarterly Issues)

Subscribe now


Void your warranty, violate a user agreement, fry a circuit, blow a fuse, poke an eye out. Make: The risk-takers, the doers, the makers of things... Welcome to Make: Online!


CRAFT Maker Shed Maker Faire MAKE television
MAKE: en EspaƱol MAKE: Japan


Check out all of the episodes of Make: television

Make: Science Room

Connect with MAKE

Be a MAKE fan on Facebook MAKE on Facebook
Visit our Facebook page and become a fan of MAKE!
MAKE on Twitter MAKE on Twitter
Follow our MAKE tweets!
MAKE Flickr Pool MAKE on Flickr
Join our MAKE Flickr Pool!
    make_tips on Twitter

    MAKE's RSS feed is here.
    Add MAKE to iGoogle - GoogleGoogle.
    How to add MAKE to your RSS reader - Real simple.
    Add MAKE on FriendFeed




    Maker SHED

    Advertise here with FM.

    Why advertise on MAKE?
    Read what folks are saying about us!

    Click here to advertise on MAKE!



    Subscribe to MAKE Magazine!

    Make: Online authors!

    Gareth BranwynGareth Branwyn
    Senior Editor


    Phillip TorronePhillip Torrone
    Senior Editor
    | AIM | Twitter


    Becky SternBecky Stern
    Associate Editor
    | AIM | Twitter


    Marc de VinckMarc de Vinck
    Contributing Writer
    | AIM | Twitter


    John ParkJohn Park
    Contributing Writer
    | Twitter


    Sean RaganSean Ragan
    Contributing Writer
    | Twitter


    Matt MetsMatt Mets
    Contributing Writer
    | AIM | Twitter


    Dale DoughertyDale Dougherty
    Editor & Publisher
    | Twitter


    Shawn ConnallyShawn Connally
    Managing Editor
    | Twitter


    Goli MohammadiGoli Mohammadi
    Associate Managing Editor

    Kip KayKip Kay
    Weekend Projects
    | AIM | Twitter


    Collin CunninghamCollin Cunningham
    Contributing Writer
    | AIM | Twitter

    Adam FlahertyAdam Flaherty
    Contributing Writer
    | AIM | Twitter



    More contributors: Mark Frauenfelder (Editor-in-Chief, MAKE magazine), Kipp Bradford (Technical Consultant/Writer), Chris Connors (Education), Diana Eng (Guest Author), Peter Horvath (Intern), Brian Jepson (O'Reilly Media), Robert Bruce Thompson (Science Room)

    Suggest a Site!

    Current Podcast

    itunesdl.gif Weekend Project: Making Char Cloth Learn how to make a cheap and effective fire starter made from an old t-shirt. To download The Char Cloth video click here and subscribe in iTunes. See Char Cloth in action with the Fire Piston from William Gurstelle.... More...

    Get the Make: Online sent via email
    Enter your email to receive Make: Online each day:



    MAKE Fascination video series brought to you by Dow

    Make: Education

    Important please read


    Subscribe to MAKE Magazine!

    Recent Posts from the Craft: Blog