Friday, November 9, 2012

Customize RD Web Access, a drop down server list

As you might know, RD Web Access provides two different ways to allow users to connect. The tab “RemoteApp and Desktops” tab contains the Remote Apps and Desktops that are authorized to user. The tab “Connect to a remote PC” allows users to specify the destination remote client, server of farm by providing the DNS or hostname.
image
In some cases you might want to pre-define the hostname users have to enter. In this blog post I’ll guide you through the process of configuring a drop down list containing destinations we want users to be able to select.
STEP 1. We’ll be editing the desktops.aspx which is located in C:\Windows\Web\RDWeb\Pages\en-US\Desktops.aspx (may differ based on the language of the Server OS). Be sure to create a backup of that file first.
STEP 2. Locate the definition of the function function GetParam(sParam, bReqd, vDefault) and add the following function specified below that function definition. We’ll use this function to retrieve selected value of the dropdown box. We can’t use the existing GetParams function as this returns the number of the select item in de dropdown box. (Uses by for example the Remote desktop size dropdown box).
function GetDestination(sParam, bReqd, vDefault)
{
    var obj = document.getElementById(sParam);
    if(obj != null)
    {
        switch(obj.tagName)
        {
            case "SELECT":
                return obj.options[obj.selectedIndex].value;
                break;
            default:
                break;
        }
    }
    else
    {
        if ((bReqd) && ((vDefault == "") || (vDefault == null) || (obj == null)))
        {
            var L_ErrMsgInvalid_Text = "%ParameterName% is not a valid or available parameter name.";  // {Placeholder="%ParameterName%"}
            var errMsgInvalid = sParam;
            errMsgInvalid = errMsgInvalid.replace("%ParameterName%", sParam);
            var retval = TSMsgBox(errMsgInvalid, vbInformation, L_sTitle_Text);
            return null;
        }
        else
        {
            return vDefault;
        }
    }
}
STEP 3. Replace the following code <input name="MachineName" maxlength="255" id="MachineName" class="textInputField" type="text"
                                    onfocus="updateConnectButtonState(this);" onblur="updateConnectButtonState(this);"
                                    onkeyup="onConnectToKeyUp(this);" onpropertychange="onConnectToPropertyChange(this);"/>
With the code: <select id="MachineName" style="width: 270px" name="MachineName">
                                        <option value="rds01.lab.local" selected="selected">rds01.lab.local</option>
                                        <option value="rds02.lab.local">rds02.lab.local</option>
                                        <option value="rds03.lab.local">rds03.lab.local</option>
                                    </select>

STEP 4. To make sure the connect button is always available find the following string and remove the part disabled="disabled"<button type="button" id="ButtonConnect" name="ButtonConnect" disabled="disabled"
STEP 5. Replace the following piece of code
var RDPstr = "full address:s:" + GetParam("MachineName", true, "") + "\n";
With the code:
var RDPstr = "full address:s:" + GetDestination("MachineName", true, "") + "\n";
STEP 6. The end result should look like something below:

Upon clicking Connect a RDP session to the selected destination is launched.
image




7 comments:

  1. Thank you! Instructions were super helpful and this will make a big improvement in our RD Farm rollout.

    ReplyDelete
  2. Thanks for the feedback, appreciate it!

    ReplyDelete
  3. This is great. How could I get the server names to populate with the list of servers available to the current logged in user? Each user might have different servers available to them based on their RAP Network Resource group.

    ReplyDelete
    Replies
    1. Sorry for the 2-year old Necro-post, but did you ever get an answer to this? I'm currently tasked with doing exactly as you just described.

      Please tell me your solution wasn't to purchase Citrix or VMware View. Cheers.

      Delete
  4. Hi,

    That is a brilliant job Freek.
    I would like to start a program when connecting to a remote server (as feasible via RDP)
    By any chance, would you know how to do that (from this desktops.aspx) ?
    Thank you

    ReplyDelete
  5. I am able to generate the drop down list but getting the following error when I click Connect button

    "to use this web site your computer must be running the remote desktop connection (RDC) client. To continue install the latest RDC client and the most recent updates from the Microsoft Web site and then try again.
    What is the workaround?

    ReplyDelete