Command line to close RDP sessions

Posted on 2009-04-30
Last Modified: 2013-11-21

can someone write down here a command line that can close terminal services session?
sometimes I try to RDP to a machine and it says something about the maximum connection reached.

Question by:jskfan
    LVL 95

    Accepted Solution

    Install the Adminpak.msi on your computer and then use the Terminal Services Manager MMC to connect to the remote system and close the idle/disconnected sessions.  (I know of no command line that will do it),.
    LVL 13

    Expert Comment

    LVL 13

    Assisted Solution

    These will also work:
    mstsc -v:servername -console
    "reset session sessionid /server:theserver_or_ip"

    Assisted Solution

    Just to add on further to here, usually the "Server has reached its maximum number of connection" error occurs due to the fact that the server is set to accept the default number of concurrent connections, which is 2 RDP & 1 Console switch.

    Try using the console switch "mstsc servername /console" and check if your able to log in.  If still cannot then, you may try marine7275: to log off any users remotely from another server.  However, you will need to find out which sessions are active or disconnected before that, use below to check it:

    QUERY USER /server"servername_or_ip
     This should return the list of users logged onto the server at that point in time, check for the "ID" and the "State" column and jot down the ID for only disconnected users, if there are any.

    Then to log off the session user the "reset session sessionid /server:theserver_or_ip" this should free up one connection for yourself.  Hope this helps.



    Author Comment

    when I run this command:
    QUERY USER /server"servername_or_ip

    I get this:

    'query' is not recognized as an internal or external command,
    operable program or batch file.

    Assisted Solution

    Ooops just noticed that the command is with the : not " that is why you get the incorrect operator error.

    QUERY USER /server:servername_or_ip

    And then do the rest of the troubleshooting i.e.:

    Check for the "ID" and the "State" column and jot down the ID for only disconnected users, if there are any. Then to log off the session user by:
    RESET SESSION sessionid /server:server_or_ip"      

    This should free up one connection for yourself.  Let us know how to get on.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    My previous article  ( one possible method to get SCCM 2007 installed an…
    Know what services you can and cannot, should and should not combine on your server.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now