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
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:
const string L_SessionOptions_Text = "Session options";
const string L_AdminSession_Text = "Connect to the administrative session of this PC";

Adding the form elements to the page


Next, we'll need to add the actual page elements that will display the form. In the document, search for the following section of code:

<!-- ******************** Hidden Row for 'Additional Options' ******************** -->
<tr>
    <td>
        <table cellpadding="0" cellspacing="0" border="0"  id="opt_panel" style="visibility: hidden;">

Add the following block of code immediately after (if you have applied the multi-monitor code from my previous post, you can add the following code after that block instead):

<tr>
    <td><b><%=L_SessionOptions_Text%></b></td>
</tr>

<tr height="7">
    <td></td>
</tr>

<tr>
    <td>
        <table cellpadding="0" cellspacing="0" border="0">
            <tr>
                <td width="7" align="left" valign="top"><input type="checkbox" value="OFF" id="xAdminSession" name="xAdminSession"/></td>
                <td width="7"></td>
                <td><label for="xAdminSession"><%=L_AdminSession_Text%></label></td>
            </tr>
        </table>
    </td>
</tr>

<tr height="20">
<td></td>
</tr>

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.

In the file, search for the following line of code:
RDPstr += "autoreconnection enabled:i:1\n";
On the next line, add the the following line of code:
RDPstr += "administrative session:i:" + GetParam("xAdminSession", false, "0") + "\n";
Save the Desktops.aspx file. You should now be able to log into RDWeb to verify the page has updated. This is 

No comments:

Post a Comment