Windows DevCenter    
 Published on Windows DevCenter (http://www.windowsdevcenter.com/)
 See this if you're having trouble printing code examples


Windows Server Hacks: Shadowing Remote Desktop Sessions

by Mitch Tulloch, author of Windows Server Hacks
11/08/2005

Shadowing Terminal Services sessions is a cool feature of Windows Server 2003 that lets you remotely control the desktop session of another Terminal Services user. You can even shadow the console session, that is, the session which the interactively logged-on user experiences at the server's console. This console session is also known as "Session 0" since it is the base or default session on a terminal server.

Let's start by reviewing how to connect with and shadow the console session on a W2K3 terminal server from an XP client machine. First you have to enable remote control on the terminal server, which in my test scenario is a standalone machine in a workgroup. You can do this as follows:

  1. Click Start, then Run, type gpedit.msc and click OK to open the Group Policy Editor.
  2. Expand Computer Configuration, then Administrative Templates, then Windows Components, and finally Terminal Services.
  3. Open the policy setting named "Sets rules for remote control of Terminal Services user sessions" and enable this policy and set the Options listbox to "Full Control with user's permission" as shown in Figure 1:

Figure 1
Figure 1. Enabling remote control of terminal server sessions

Next, open a command prompt on the XP client and type mstsc -v:servername /f where servername is the IP address or name of the terminal server. This will open a Remote Desktop session from the client to the server.

Now open a new command prompt within the Remote Desktop connection you have established from your XP client and type shadow 0 to request shadowing of the console session (session 0) on the terminal server. A dialog box should appear on the terminal server's desktop saying "<Your credentials> is requesting to control your session remotely, Do you accept the request?" Click Yes and the Remote Desktop session you have open on your XP client machine should show exactly the same as what appears on the interactively logged-on desktop of the terminal server. For example, if you open Notepad on the server, Notepad should likewise appear in the shadowed session on the client. Figure 2 shows the shadowing XP client and the shadowed terminal server side by side in a Virtual PC environment.

Thumbnail, click for full-size image.
Figure 2. The shadowing XP client and the shadowed terminal server side by side in a Virtual PC environment. Click for full-size image.

Note that to terminate shadowing in your session from the client, press Ctrl-plus key-* where the * key from the numeric keyboard must be used.

Connecting to the Console Session Directly

You can also connect directly to the console session on a terminal server from an XP client. To do this, open a command prompt on the XP client and type mstsc -v:servername /f -console but before you do it, open Notepad on the terminal server's console and type something in it. The reason for doing this is that when you connect from the XP client to the console session of the terminal server, the interactive console on the server locks. Figure 3 shows a Remote Desktop session on an XP client connected to the console session on a Windows Server 2003 machine that has Remote Desktop enabled, again within a Virtual PC environment.

Thumbnail, click for full-size image.
Figure 3. Remote Desktop session connected to console session on Windows Server 2003 with Remote Desktop, in a Virtual PC environment. Click for full-size image.

Shadowing the Console Session on Windows XP

Things work a little differently, however, in Windows XP, which has a scaled-down version of Terminal Services that only allows two (count them -- two) user sessions simultaneously. For example, say I have a box named XP194 on which I've enabled Remote Desktop using the Remote Desktop tab of System properties in Control Panel. I can then open a Remote Desktop session from XP191 to XP194 (doing so locks the console on XP194, but it does leave the console session running and any open applications running on it as well). If I try and open another Remote Desktop session to XP194, this time from XP192, my previous session initiated from XP191 is terminated. That's because Remote Desktop on XP only allows two user sessions -- in the case of Remote Desktop this is one remote session plus the console session -- at any one time.

(This is different, by the way, from how Remote Desktop works on Windows Server 2003. For example, if I enable Remote Desktop on a W2K3 box I can then open a Remote Desktop session from both XP191 and XP192 and still have access to the local console on the W2K3 box. But if I try and open a third connection from XP193, I get a message saying "The terminal server has exceeded the maximum number of allowed connections.")

Despite the limitations of Remote Desktop in XP, there is a cool hack that lets you actually shadow the console session on a Windows XP machine, and it works like this in my Virtual PC environment:

  1. First I open a Remote Desktop connection on XP191 to my Windows Server 2003 machine that has Remote Desktop enabled. This W2K3 machine will act as a kind of intermediary for our purposes.
  2. Now within the Remote Desktop session I just opened on XP191, I open a new Remote Desktop connection to my target machine XP194. The interactive console on the target machine now locks as expected.
  3. Next, from another XP box (XP192) I open a second Remote Desktop session with my Windows Server 2003 machine. There are now two remote sessions to my W2K3 box, one from XP191 and the other from XP192. In addition, within my remote session on XP191 I have remotely connected to XP194, my target machine.
  4. Finally, within the session opened on XP192, I start a command prompt and type shadow 1 to shadow the session opened in step 1 above. Then I switch over to XP192 and click Yes to the prompt saying "<Your credentials> is requesting to control your session remotely, Do you accept the request?"

To test the result, I tile my Virtual PC windows so I can see both XP191 and XP192 simultaneously. Then on XP192 I click the Start button and the Start menu immediately appears on XP191 as well (see Figure 4). But since my session on XP191 is actually the console on XP194 (connected through my W2K3 box), the result is that from XP192 I am shadowing the console session on XP191 (which is XP194). Pretty cool!

Thumbnail, click for full-size image.
Figure 4. Viewing XP191 and XP192 simultaneously. Click for full-size image.

Mitch Tulloch is the author of Windows 2000 Administration in a Nutshell, Windows Server 2003 in a Nutshell, and Windows Server Hacks.

Windows Server Hacks

Related Reading

Windows Server Hacks
100 Industrial-Strength Tips & Tools
By Mitch Tulloch

Return to the Windows DevCenter.

Copyright © 2009 O'Reilly Media, Inc.