How-To Geek

Command Line Hack for: "Terminal Server Has Exceeded the Maximum Number of Allowed Connections"

If you’ve worked on a network with Windows servers, you’ve encountered this error message at least 37,000 times:

“The terminal server has exceeded the maximum number of allowed connections. The system can not log you on. The system has reached its licensed logon limit. Please try again later.”

This problem happens because Windows only allows two remote terminal services connections when you are in administrative mode, and you’ve either got two people already on that server, or more likely, you’ve got a disconnected session that still thinks it is active.

The problem with this error is that you have to actually get on the server console to fix the problem if the server isn’t in a domain. (If you are in a domain, then just open Terminal Services Manager and log off or disconnect the sessions)

To use the command line hacks, you might need to run them from another server if your local operating system doesn’t include the commands. You will also need to make sure that you are logged onto that server with an administrative account. The easiest way to do that is just map a drive (you don’t have to use a drive letter unless you choose to)

net use /user:[username] \\servername\share

Here’s a command line hack that you can use to figure out what sessions are connected to the server. Note that you could substitute the IP address for the server name.

query session /server:servername

Sample output:


Now we know that the session ID of the offending session is 2. We can use that in the next step, which is using the reset command to log off that user.

reset session [ID] /server:servername


This command won’t display any output, but when we run the query command again, we should see that the session has now been disconnected:


Note: Thanks to my friend Todd for this one.

Lowell Heddings, better known online as the How-To Geek, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on if you'd like.

  • Published 03/19/07

Comments (116)

  1. Sathish kumar

    Great help for me to identify this command

  2. Mike Scott

    That is a great tip. I usually just use “mstsc /v:servername /console” to connect to the console session, and then I can close the bad sessions.

  3. ec

    Another tip, if you have sql server and have enabled xp_cmdshell you can use these same tips via query analyser.

  4. Thomas

    Very good solution for such a problem.
    Thanks for sharing such command lines.

  5. Dima

    Thanks! It saved me a trip to the data center!

  6. Wayne

    Hi Folks,
    I really do run into this problem about “37000” times a week. This solution is a life saver.
    Thanks a bunch!

  7. PKRao

    Cool solution mate.

  8. Thankful soul


    Just hit bed and got a call from a customer about this. You saved my night of sleep.

  9. UnklPty


    Just type in tsadmin in the run or command prompt, connect to the server in question, and disconnect, reset, or log off the offending/stale session.

  10. Jaime Gomez

    Thanks for this solution. Excellent.

  11. Tracy

    You saved from going to dc’s control panel, and rebooting my server each time i have this issue.. Thanks

  12. Pierre Fourie


    My fellow geeks i’m a white South-African and this line just saved my ass from being fired at work.

    THANKS A LOT !!!!!

  13. Jilesh

    Thanks. That saved me a lot of hassle.

  14. Vasily

    Awesome, guys! It is such a needed tip!

  15. yabbi

    When i type in the commands, my XP Pro cmd tells me query is not recognized

    Any idea why?

  16. Phani

    Great, it saved our life at 12:00 am, we have a migration work on production and got this error, your article saved us. Thanks

  17. Mrinal

    This tip is really very very useful. It has helped my Data migration, restore and backup

  18. Gaurav shrivastava

    Thanks, It worked like charm.

  19. Zayne S Halsall

    Excellent tip. Much more useful than the “Start -> Run -> mstsc -v:x.x.x.x /console” tip that is floating around the Net. Our systems use specific admin users and I would’ve had to figure out how to login to the relevant server from my Mac, in my Windows VM image, as a normal user, using “Run As…”, to launch the console on the server… just too much when I needed it.

    By contrast, your tip explained the need to get onto another server having the tools, and the exact commands to use and output to expect. Neat, concise, and working. Thanks.

  20. Paul

    When using Administrative mode, Windows Server 2003 allows 2 concurrent connections plus a console connection. To access the console connection, type mstsc /console from Start->Run.

  21. Gaurav Verma

    Really kewl..
    thanks a ton…

  22. Pattycakes

    Thanks for documenting this tip. You just saved me 30 minutes of driving, and kept the world a little greener. :>

  23. Blake

    This is amazing. But…I don’t want to kill someone else’s connection just to get on (it’s okay if the connection has been inactive for a while, but what if someone’s using it?). Isn’t there a way of just allowing more connections?

  24. Anton Venema

    Excellent tips – clean and well-presented. For me, the query and reset commands were found in %systemroot%\system32\dllcache (XP Pro SP3). Here’s a batch file that will loop through these commands to your satisfaction:

    SET EXEC=%SYSTEMROOT%\system32\dllcache

    SET /P SERVER=Enter IP or server name: %=%

    SET /P USER=Enter user name: %=%

    SET /P PASS=Enter password: %=%

    NET USE \\%SERVER% /user:%USER% %PASS%


    %EXEC%\query session /server:%SERVER%

    SET SID=
    SET /P SID=Enter session ID to reset: %=%

    %EXEC%\reset session %SID% /server:%SERVER%

    SET /P CONT=Reset more sessions? %=%

    IF /i “%CONT%” EQU “y” GOTO START

    SET /P REMOTE=Launch remote desktop? %=%

    IF /i “%REMOTE%” NEQ “y” GOTO END

    mstsc /v:%SERVER% /f


  25. djsayz

    nice Web :).

    Xpoision RulZz

  26. jpavly

    Can’t tell you how much I love this article, thanks a buck. :D

  27. FuzzyLogic

    Excellent, saved a lot of pain and frustration.
    This tip is ideal for two main reasons:
    1. When the console session is in use, “mstsc -v:x.x.x.x /console” is of no help.
    2. When the server in question is not a member of your domain (vendor box,) tsadmin is of no help, either. Unless there is a special trick to running that one with alternate credentials and having it actually open (tried, failed on my workstation.)
    Add to that the fact that our physical console was unresponsive (untimely and unrelated issue) and this really saved the day.

  28. malek

    I can,t access to QUERY SESSION command!!!

  29. PeBr

    Thanks for this excellent tips.
    Helped me a lot! No need of the IT guys anymore in this area……..

    I couldn´t reach the query command myself from the Windows XP client operative system neither.
    Though from Windows 2000 Server no problems!!!!

  30. Mourad

    Good stuff mate, thx for that.

  31. User

    Maybe prevention would help also… Just configure your server’s Remote Sessions to logout after x idle minutes, etc…? Way better than having to reset sessions all the time…

  32. Jon

    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:

  33. Simon


    I have tried but still failed to end a session on my web server, port 80 is open and 3389. I just can’t get connected… I’d rather not have to fly over to Spain just to re-boot…

    I try:

    net use /user:Administrator \\193.171.XXX.XXX\c

    I get:
    System error 67 has occurred.
    The network name cannot be found.

    I have tried using c$ , d, d$

    And every name of every Microsoft share name there is still no joy.

    This would be REALLY handy if I could get it to work.

    Any ideas?

  34. Jon

    Simon please contact me with the email addy on my website, I will try to help you work it out or find an additional solution.

  35. Mikey

    Very nice … good job

  36. sfcg

    Nice one. Our finance server is the only machine not on the domain, due to running such an old version of the software. A developer let his session get idle, which a local policy typically resets, but for some reason got stuck.

    Due to this not being on the domain, Terminal Services Manager, and qwinsta/rwinsta didn’t list any of the sessions.

    I totally forgot also that once you authenticate to a server over a command line session, you stay authenticated to that server until the command line closes.

    I was half dressed and almost out the door when I looked this up. Worked great. I got to go back to bed and not be angry the next day over a midnight Data Center mission.


  37. S V Chethan

    Thanx a ton is this is really cool

  38. Vis

    Nice one Hats off

  39. Jesse

    Awesome. I wasnt able to do a console rdc on my issue so this came in real handy. I just had to connect to a server with the “query” command and then everythign worked great

  40. Zameer

    You can use Qwinsta /server (Server name / IP) to query sessions and use rwinsta /server (Server name / IP) (session ID) to reset.

    Qwinsta /server msnexchange (replace msnexchange with the server name or IP)
    Rwinsta /server msnexchange 1 (replace msnexchange with the server name or IP and 1 with the session ID which you wanted to disconnect.

    Njoy :)

  41. Arunodaya

    Really this command is very help to the new user as well as experience.


  42. LuckyUser

    I tried this tool by JR Software.. its worked just puurrfect!!

  43. Milan

    Great tip!

  44. Ahmed Ghaith

    Thanks and grateful.

  45. Alex

    Run: mstsc -v: /f -console /admin

  46. Mike

    How do you log out of your command line session when you are done?

  47. Ryan

    WOW! Thanks. saved me an international trip to our production plant.
    Thank you so much

  48. ryencx

    this tip saved me. plus, i enjoyed doing it in the command line =)
    Thank You so much!

  49. Frederiek Van Hoornick

    if you have an xp machine and only one server where you need to get on to. Use the psexec tool (download it from the microsoft site)

    start a cmd window on your xp
    use the command net use /user:administrator \\server01\c$

    psexec \\server01 cmd

    and then the query session
    and reset session


  50. Victor

    Thanks! This was exactly what I was needing.

  51. leo

    Thanks.. you made my day..

  52. frank

    What a nice why of solving issues, very helpful.


  53. alex

    very great tip.
    and it works over ssh, so it can be done from any linux station connected to the windows machine

    thank you very much :)

  54. Roland

    Another way to do this is tsdiscon. See

  55. Tyler Durden

    I work for the US army and this tip just saved our country from trouble. Thanks!

  56. Jones Mahmud

    This was very useful, simple and effective documentation.

    Thank you.

  57. gaurav bansal

    It is bast for us
    I totally forgot also that once you authenticate to a server over a command line session, you stay authenticated to that server until the command line closes.

    I was half dressed and almost out the door when I looked this up. Worked great. I got to go back to bed and not be angry the next day over a midnight Data Center mission.


  58. adonis

    OMG ! This is amazing guys! Thanks a lot

  59. cornelius

    Thanks for command line code. Save me a trip to the ofice.

  60. julius

    Query session is not recognized as an internal or external command, operable program or batch file.
    what does this mean?

  61. jim

    it is nice and bad there is too many ordering for hacking and command like matrix code this is my email if any body wanna a help in hacking programs and this is my email

  62. Marcos Ferreira

    thank you so much for the tip !
    “query session” and “reset session” commands saved my life.
    best regards

  63. s

    Really this solution helped me a lot

  64. s

    thank you ..this solution really helped me a lot

  65. Cotswolds B&B

    This has saved my life soooo many times over the past few years – thought I better stop by and send my thanks..

  66. Srini

    Thanks a lot. It saved me from a nightmare….

  67. Surya

    Thanks .. it still works like a charm :)

  68. Ajith

    Thanks a lot guys!

  69. manoj singh

    how to hack a clients to server in command line.

  70. Ghanshyam

    I used this tool Remote TS Manager by JR works perfect!! even from a XP system!! Thanks Jon saved lot of my time running those commands..:)

  71. cliff

    gr8 tip, works like magic

  72. lots of good tricks here

    thanks all!

  73. Gaurav

    Hi the query command is present in windows XP also under c:\windows\system32\dllcache. Please add that information in your tip

  74. kishore

    Great !! Great !! Great command

  75. charlie siswick

    awesome post…thank you….as usual simple solution to a complicated problem

  76. Sanjay


  77. CNC Admin

    It saved my trip to Data Center. Nice tip. Thank You. Oracle DBA

  78. Mahidhar

    Thanks a lot for this. The instructions were very useful

  79. Brian


  80. xyz

    nice one

  81. Vic

    My XP PRO SP2 tells me query is not a recognise batch command.

  82. Gabby

    Great tip!

  83. Ionoi

    Thanx, man!
    Useful topic.

  84. Lenny

    Excellent tip – helped me out this morning – THANKS !

  85. abdullah

    Thanks man, a useful tip.
    It would be good if the query command provides also the time that the session is started.

  86. nimeni

    Thanks a bunch!

  87. Allan

    Good tip, thanks.

    There is another which we use:

    Start > Run and type:

    mstsc /admin

    Note it will knock off the logged in Admin user

    Good luck.

  88. radhakrishna

    thanks a lot!!

  89. Dayo Okesola

    Thanks men! you are a real life saver!

  90. Lance

    Great tip — many thanks!

  91. Ashish Shukl

    Thanks a lot for this solution.

  92. JohnC

    Thank you; worked like a charm! Saved me a trip to the data center!

  93. Michael Birkinshaw

    Thank you for the command line hack.

  94. Vazi

    Wonderful command..!

  95. Franco

    Thanks for the script Anton, worked like a champ!

  96. hacky

    hi in my college facebook is blocked can u please help me get in through some mean..pls pls

  97. Kean'o

    Could not get the main script above to work with my permissions on the network but the tip from Allan works great, so thanks

    Good tip, thanks.
    There is another which we use:
    Start > Run and type:
    mstsc /admin
    Note it will knock off the logged in Admin user
    Good luck.”

  98. Eiril

    Frederiek Van Hoornick <— you roxxx!! thanks man =)

  99. MNA

    Dude Great Tip!!!! Saved us much trouble… U rock….

  100. boss

    this was great help my friend …,

  101. sleepwalker

    Thanks mate! It saves me alot of time. Thumbs up!

  102. Saran

    Thanks dude, this had really helped me..
    cheers, Saran.

  103. kashan

    give m i.d back

  104. chris

    Nice, thanks for the tip. I put this in a script that automates the steps nicely using variable machine names.



    ECHO Script purpose: Log out any RDP session from a specified server.

    SET /P SERVERNAME=”Enter a server name to view it’s RDP sessions: ”


    ECHO Current session details
    ECHO ————————————————————————–


    ECHO ————————————————————————–

    SET /P SESSIONID=”Enter the session ID number to log out: ”

    ECHO Working, please wait…



    ECHO Refreshed session info
    ECHO ————————————————————————–


    ECHO ————————————————————————–


    SET /P STARTOVER=”Press 1 to start over, or any other key to exit: ”



  105. Carl

    Thank you so much! I was remote working and absolutely need a connection on my server!

  106. BurtDakarax

    Frederiek Van Hoornick <— you double roxxx!! thanks man =)

    (with reference to Eiril)

  107. Murali

    Really Usefull tip..

    Thanks alot

  108. Filipe

    Thanks a lot, this is a really helpful tip.

  109. George

    Easier way to do it is from a command prompt run “mstsc /v:x.x.x.x /admin” where x.x.x.x is the server you can’t remote into, then once in open Terminal Services Manager and kill all the sessions except your own using first the “Disconnect” and then “Reset” options by right-clicking the different connections you see. Problem arises because people have tendency to just close a remote connection window out instead of logging off and it leaves an active remote session on the server

  110. IT Admin

    Rather than reset session, (which forcefully kills a session without saving settings), why not use command prompt to log off the session normally? much more recommended command line:

    logoff 2 /server:servername

    use it all the time.

  111. Sriman

    Cool dude. worked fine for me.

  112. pradeep

    Thanks……Dude…………it work, you save my 1 day

  113. Nadeem Ahmad

    Thanq so much……keep it up …Best of Luck…

  114. Forsberg

    Thanks for post, sure saved alot of peoples time! When I first did this, the net use command failed with no logon servers available. After supplying both servername and the password directly in the command line it worked like a charm:

    net use q: \\\C$ /user:SERVERNAME\Administrator password

  115. Sascha

    Thanks for that great information. You save my day (and probably the whole night)! ;-)


  116. Miami Tech

    Props here! Thanks

More Articles You Might Like

Enter Your Email Here to Get Access for Free:

Go check your email!