Scott Forsyth's Blog

Postings on IIS, ASP.NET, SQL Server, Webfarms and general system admin.

Cloud Resources

IIS Resources

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.

Posted: Dec 30 2003, 04:20 PM by OWScott | with 60 comment(s) |
Filed under:

Comments

David Cumps said:

Very nice tools, thanks for the information, didn't know of there existence :)
# December 30, 2003 8:07 PM

Jerry Dennany said:

Thanks - very usefull information!
# December 31, 2003 7:47 AM

Kris Anderson said:


Great! Thanks for sharing. We've had this same problem, and didn't know of any workaround.
# December 31, 2003 8:59 AM

Wayne Hall said:

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.
# January 19, 2004 9:37 AM

Wayne Hall said:

Found it -- it's called tsdiscon and works like a champ.
# January 22, 2004 5:01 PM

Scott Forsyth said:

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.
# January 22, 2004 5:11 PM

Nick Clark said:

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
# February 28, 2004 6:39 AM

Kevin Severud said:

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.
# March 3, 2004 1:55 PM

Scott Forsyth said:

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!
# March 3, 2004 11:18 PM

Scott Forsyth said:

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.
# March 3, 2004 11:20 PM

nilesh said:

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
# March 9, 2004 10:06 PM

Scott Forsyth said:

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?
# March 10, 2004 9:19 AM

Stuart said:

Very useful. Didn't know these tools existed.
Many thanks - helped us out of a spot.
# March 25, 2004 6:13 AM

Dave said:

Cool tools - got any to extract the IP address of the remotely connected client to a log file along with the session details?
# March 26, 2004 9:59 AM

Jay said:

Another satisfied customer... Terminal Server Manager didnt show the problem server in my domain so these command line queries were a huge help
# March 30, 2004 8:10 AM

Andy Lewis said:

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.
# April 1, 2004 7:39 AM

David said:

We were dealing with this issue for some time, thank you for posting this information-extremely helpful!
# May 6, 2004 2:51 PM

brandon said:

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?
# June 4, 2004 3:03 PM

Scott Forsyth said:

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.
# June 4, 2004 3:07 PM

brandon said:

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

# June 4, 2004 3:17 PM

Scott Forsyth said:

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.
# June 4, 2004 3:42 PM

brandon said:

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.
# June 4, 2004 3:51 PM

Chaostya said:

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
# June 8, 2004 10:24 AM

Marcus said:

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!
# June 9, 2004 4:18 PM

Ryan said:

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!
# June 12, 2004 6:56 PM

Ryan said:

mmkay -- I think my problem lies with RPC -- thanks so much for the page!
# June 13, 2004 2:10 AM

Chaostya said:

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).
# July 9, 2004 9:36 AM

Patrick said:

No dice from 2k on 2k3 sessions hubg wit tsdiscon or rwinsta OR the GUI (server not seens but accessible from commandline).
# July 23, 2004 7:10 PM

Scott Forsyth said:

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.
# July 23, 2004 8:19 PM

Anthony said:

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

# July 31, 2006 4:48 AM

Puneboy said:

This is a life saver !!!

# October 5, 2006 11:25 AM

Rob K said:

Thanks so much for this great info.

# October 19, 2006 6:11 AM

Shireesh Thanneru said:

This indeed is a life saver!!!

# October 25, 2006 3:10 PM

Kelly said:

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

# October 29, 2006 12:36 PM

Nick Taylor said:

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?

# October 31, 2006 6:58 AM

Loops said:

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

# October 31, 2006 1:23 PM

Steve L said:

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!

# November 15, 2006 12:42 PM

Liam said:

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.

# December 13, 2006 12:17 AM

Steve L said:

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.

# January 16, 2007 2:43 PM

Chad deQuevedo said:

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.

# January 18, 2007 8:40 AM

drmthtr said:

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.

# February 22, 2007 11:57 AM

Leopold said:

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

# February 23, 2007 6:38 AM

Andy said:

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!

# March 2, 2007 12:15 AM

Sunny said:

time saver.

Thanks alot.

# March 16, 2007 5:41 AM

jobd said:

thanks, this helped me out bigtime!

# March 20, 2007 2:59 PM

adisoft said:

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

# April 15, 2007 8:02 AM

Firmin Dani said:

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

# June 6, 2007 6:49 AM

Jonathan said:

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

# August 4, 2007 11:28 AM

Alec said:

Does anyone know how to extend time out session in Vista RDP ?

# August 5, 2007 7:32 AM

Scott Poste said:

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

# August 6, 2007 10:00 AM

StuD said:

Thanks for the information! helped a treat

# January 21, 2011 12:36 PM

Wally Munchovie said:

This is THE end-all to this problem

mstsc -admin (your server name or ip here)

:D

# May 21, 2011 10:56 AM

OWScott said:

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.

# May 21, 2011 11:04 AM

Sundaram A said:

Thank you very much. it is really nice.

# June 23, 2011 10:41 AM

Jeff said:

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

# August 24, 2011 6:08 AM

Vishal said:

very helpful..thank you :)

# August 31, 2011 2:53 AM

Mons said:

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

# September 28, 2011 5:59 PM

Napel said:

Thanks these tips were helpful

# October 26, 2011 5:08 PM

brendan said:

Excellent - very useful and simple commands.

thank you

# June 21, 2013 5:44 AM

Dennis Lonndon said:

Perfect! You saved me.

# August 5, 2013 9:39 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)