Managing Terminal Services Sessions Remotely

I regularly administer Windows 2000 Server and Windows Server 2003 machine using Terminal Services.  In W2K I use Terminal Services in Administration mode and in W2K3 I use Remote Desktop.  Basically this is the same thing but it's packaged a bit differently on the two OSes.  In both situations there are only 2 users allowed for administration so occasionally both are used up and I can't access the server.  This may happen if two people are legitimately using the servers or if someone forgot to log off.  Yes, I do have the settings set to automatically disconnect and/or log off a user after X minutes of inactivity but even with that there are times when I need to be able to manage this remotely.

You would think this would be as easy as connecting to the remote server by adding the Terminal Services Manager snap-in to a MMC console or remotely stopping and starting the service (in a pinch).  Strangely, these obvious solutions aren't available.  Terminal Services Manager doesn't exist as a snap-in to connect to a remote machine and because the TermService service is a core system service, you can't even stop it on the local machine, let alone a remote one.

Fortunately there is an easy solution.  Windows 2000+  (includes Windows XP and 2003) have two command-line tools called qwinsta and rwinsta that can query and reset a remote session.

For example, let's say that I can't gain access to a server using Terminal Services because both sessions are used up.  I can use another server to check the status of the first one.  As long as the logged in user has administrative rights on the non-accessible machine I would run this:

qwinsta /server:12.12.12.12

Where 12.12.12.12 is the IP address or name of the non-accessible machine.

This will display something like this:

> qwinsta /server:12.12.12.12
 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
 console                                     0  Conn    wdcon
 rdp-tcp                                 65536  Listen  rdpwd
 rdp-tcp#470       Bob                       1  Active  rdpwd
 rdp-tcp#471       Jane                      3  Active  rdpwd

Now I know that Bob and Jane are the two that are logged in.  Since Jane left the office 20 minutes ago I know that she forgot to log off.  I don't know where Bob is but I only need one session so I'll ignore him for now.

To disconnect Jane's session I would type this:

rwinsta /server:12.12.12.12 3

Notice the 3 which is the session ID I found from using qwinsta above.

Yet another option with W2K3 is a new feature that lets you connect to the desktop directly and gain a 3rd session. 

If you're like me, you probably noticed that rwinsta and qwinsta seems like strange names.  This came from the Citrix Metaframe days which Terminal Services has descended from.  It stands for:

qwinsta = Query WINdows STAtion
rwinsta = Reset WINdows STAtion

One final comment.  Microsoft has replaced these two tools with Query but since qwinsta and rwinsta is fully compatible with W2K WinXP and W2K3 I choose to use it instead.


Note: In Windows Server 2003, you can right-click on the root in Terminal Services Manager and Connect to another server.  Also, if you are in an Active Directory domain and using Windows 2000 Server, you can Connect to All Servers and access remote servers from the GUI.  But, in a Windows 2000 Server not connected to a domain, you run into the limitations that prompted this blog.

59 Comments

  • Very nice tools, thanks for the information, didn't know of there existence :)

  • Thanks - very usefull information!



  • Great! Thanks for sharing. We've had this same problem, and didn't know of any workaround.

  • Very nice to know this. I wanted to comment also that Win2k3's terminal manager does have a new feature called "Connect to server" where win2k didn't have it. However, it *still* couldn't connect to this one server I had issues with, and the command lines could.



    I still would like to be able to actually _disconnect_ a session instead of _reset_. Reset logs it out and loses everything, where disconnect would just make the session inactive, like right-clicking the session and picking disconnect.

  • Found it -- it's called tsdiscon and works like a champ.

  • Wayne, Thanks for the update on tsdiscon, I was wondering the same thing but hasn't looked into it. It works great for me too.



    As for the w2k3's connect to desktop feature, it will only work connecting to another w2k3 server. I'm not sure if you were trying to access a W2K server or not. Just an idea in case.



    There are two TS clients that are included with w2k3. One is Remote Desktop Connection in Programs -> Accessories -> Communications. That one doesn't allow the connection to desktop. But, the Remote Desktops in Administrative tools does.

  • Nice tools! Another way is to logon to another server, run TS manager, find the server in 'All listed servers' you can then disconnect or reset the sessions on the other box.

    btw .. like the site ... just browsing through the articles atm. cheers

  • Regarding the msg from Scott Forsyth: Remote Desktop Connection will connect to the desktop (aka console) if you add -console to the command line for mstsc.exe.

  • Nick, I'm not sure how I've overlooked something so obvious. I can't tell you how many things I tested before finally settling on qwinsta and rwinsta as the best solution. As you promised, it worked perfectly. Thanks!

  • Kevin, great feedback. I tested this and it worked great. Since I prefer the mstsc.exe over tsmmc.msc, I'm sure I'll put this to good use.

  • has anyone found a way of setting up a log file for all this terminal sessions? i am using win2k and client is using remote desktop on xp pro.

    i have checked all the settings and cannot find any option to create a log file.

    Nilesh

  • Nelish, what do you mean by a log file? Do you want to record every time you visit a server or would you like a list of servers that you can easily click on?

  • Very useful. Didn't know these tools existed.

    Many thanks - helped us out of a spot.

  • Cool tools - got any to extract the IP address of the remotely connected client to a log file along with the session details?

  • Another satisfied customer... Terminal Server Manager didnt show the problem server in my domain so these command line queries were a huge help

  • Very useful, thanks Scott! Now I have to work out how to get RPC working with NetBIOS turned off.



    Dave, you should be able to see who has logged on to your system in EventViewer (security). It should show audit events for each user that has logged on although there is no easy was to see if they logged on using RDP AsFarAsIKnow.

  • We were dealing with this issue for some time, thank you for posting this information-extremely helpful!

  • Using WinXP to remote desktop to a 2003 server, I cannot view some 3rd party applications that are running. I used to be able to remotely see and manage them, but somehow that function is no longer working. Is there a service or security feature that may have changed or need to be started to view these apps?

  • You shouldn't have a problem viewing them but keep in mind that in Windows Server 2003 you have 3 sessions: the desktop and 2 remote sessions. So, if you started the program at the desktop, make sure you connect to the desktop and not one of the 2 remote sessions.



    Kevin Severud (comments above) explained how to connect to the console: mstsc -console from the command prompt.

  • Sorry to ask, but how do you go about adding -console to the cmd line of mstsc.exe?

    and, do I do this at the server or the XP client?



    (thanks, your response was very quick!)



  • Brandon, Sure thing: From your WindowsXP machine, go to the command prompt and type: "mstsc -console". This will open the Remote Desktop program, but when you log in it will place you on the desktop of your Windows Server 2003 machine rather than 1 of the 2 remote sessions. My guess is that your 3rd party programs on open there.

  • Worked great! I had thought maybe I would have to add the "adminpak" for 2003 to get the remote desktops snap in for the mmc console.



    thank you for your assistance.

  • Info about this can be found in standard windows help. But can you assist me in remotely obtaining information about session that I can view in Terminal Services Manager (Information tab) in command line. So I can tell from wich machine the session connects and so on. In "querry session" I can only tell username. Maybe someone knows third-party tools for doing this ?

    Contact info: chaostya@ukrpost.net

  • In response to Nick Clark's post..To simplify firewall rules between zone's we've forced SMB over TCP (disbled netbios). When you do this TS Manager can no longer see remote computers in the browse list...so these command line utils are a gold mine of a find for me, thanks!

  • What's the trick for using this to reset terminal services on a machine with just its IP address (not on the local network) -- do I need to be logged onto my machine with a user account of the same username and password? My last resort is to write an asp page that will execute the appropriate command lines, but I'm not sure I want to do that! Thanks!

  • mmkay -- I think my problem lies with RPC -- thanks so much for the page!

  • To Ryan:

    I wrote a tool to connect to the machine with IP-address, view sessions, disconnect, logoff or send messages to them using Terminal Services.



    If your credentials are not enough to do the job, you will be asked to enter login/password (using standard Windows features, not ny own).

  • No dice from 2k on 2k3 sessions hubg wit tsdiscon or rwinsta OR the GUI (server not seens but accessible from commandline).

  • Patrick, your issue might be unrelated to Terminal Services then. Can you ping the server? How about access other services on that server? Using MMC, you can try connecting to the services on the remote machine and ensure that the Terminal Services service is running.

  • Hi, this is really useful, thanks!

    What is the difference between normal RDP connection and connecting "to the desktop directly"? Is there any limited functionality, or is it really a 3rd genuine RDP connection??

    Thanks,
    Anthony

  • This is a life saver !!!

  • Thanks so much for this great info.

  • This indeed is a life saver!!!

  • Great info! Saves for a car trip to the server. great!

  • Hi Scott,

    This is really useful! I don't suppose there's an easy way of displaying this same data on an ASP page... i.e. can I get this via VBScript?

  • Thanks man, used this to good effect, got a buddy out of trouble :)

  • I was in a situation where I couldn't access the Terminal Services Manager applet at the console and all the terminal connections were in use. I used the command locally by using the server's loopback address of 127.0.0.1. Worked great!

  • Try the win2k3 server resource pack - it has the TS Manager in it that you can use to connect to any TS in your domain from an XP machine; can also view/reset/disconnect any sessions.

  • Win2k3 Server Resource Pack is great when you can access the server over the domain but the server in question for me was on a DMZ.

  • I was trying to use these tools on a web server hosted outside out network and I couldn't get them to work. I couldn't create the secure connection using Net Use or by putting \\serverip\c$ in explorer. It just wouldn't connect even though I was using the right User/Pass. Then I tried Map Network Drive using the "Connect using a different user name" option and I was in. I was able to kick off the open connections and get back into the server. I was on an XP SP2 machine connecting to a Win2k server.

  • Anybody find a free way to manage multiple connections other than Remote Desktops? Managing 150 servers would be handier from a single window, other than multiple Remote Desktop Connection windows.

  • You can also use the logoff command followed by the qwinsta session id to reset that user session

  • I've use this info to connect to the server using ssh over cygwin and clean up rdesktop sessions so that we can log in remotely.

    Really useful when we're in New Zealand and the server is in San Francisco!

  • time saver.

    Thanks alot.

  • thanks, this helped me out bigtime!

  • VERY NICE TOOLS,
    but i have anather questin
    how can i be in remote with more than 2 sessin in W2K3
    I have users which use a session to w2k3 for a program in that server.
    Thanks for sharing

  • The information provided was really useful and I was able to disonnect the sessions.

  • Thank you. Another truly informative and useful trick from your site.

  • Great tool, It just saved me from having to get the onsite admin out to reset the session.

  • Thanks for the information! helped a treat

  • This is THE end-all to this problem

    mstsc -admin (your server name or ip here)

    :D

  • Wally, for Windows Server 2000 and 2003, you're right, the hidden 3rd session is very useful. In 2008 there are only two sessions and -admin doesn't help anymore.

  • Thank you very much. it is really nice.

  • very helpful! .:D (used it on a windows 2000/2003 environment)

  • very helpful..thank you :)

  • Thanks for the help, I can't work with all these people logged into our Remote Server.

  • Thanks these tips were helpful

  • Excellent - very useful and simple commands.

    thank you

  • Perfect! You saved me.

Comments have been disabled for this content.