Thursday, April 16, 2015

Connect to the Administrative Session of a Machine Through RDWeb (mstsc.exe /admin for RDWeb!)

As a follow up to my previous post Add Multi Monitor Support to RDWeb, today I'll be showing you how to add an option to RDWeb to allow users to connect to the administrative session on a machine, or in other words, to connect to the console session. This is the equivalent of using mstsc.exe /admin but will instead function when using the "Connect to a remote PC" link in RDWeb.

Why would we need this ability? Sometimes you just need to connect directly to the console of a machine. For our environment, we needed the ability to remote directly into an RDS Session Host server. If you try to RDP into a Session Host server that is a part of a collection, there is a possibility of being redirected to a different server in the collection. The RDP client will typically throw an error message, as the server you are being redirected to was not the server you requested. By forcing the connection to the administrative session, the RDP client will bypass the redirection and connect you to the server you specified.

As with the previous article, we'll add the option to connect to the administrative session of a computer to the Options section of the Desktops.aspx page, as shown below.

Add option to connect to the administrative session of a machine

Defining the localized text

First we need to define the text that will actually display on the page. Start by browsing to C:\Windows\Web\RDWeb\Pages\en-us\ and open Desktops.aspx in your text editor of choice. At the top of the file, locate the Localizable Text section near line 20 of the file and add the following two lines:

Adding the administrative session code to the RDP file

Finally, we need to add the code that will actually enable connecting to the administrative session depending on whether the user has selected the option. This time, we'll be invoking the administrative session setting of the RDP protocol.