Automating Remote Desktop Web Connection

Automating Remote Desktop Web Connection


Remote Desktop (Terminal Services) is a very useful tool that ships with Windows XP. Actually it is also available, AFAIK, in Windows 2000 also but I think there it needs to be downloaded, configured and managed separately and I think there is a separate interface called ‘Terminal Services Manager’ over there. It also incurs a separate license. The Remote Desktop Client which gets shipped in Windows XP also has the capabilities of saving the connection details in a separate file in desktop or wherever and when you double click it, it would automatically launch the session for you.


For Windows 2000 Workstations, which do not have this Client, we can download Remote Desktop Web Connection from Microsoft. The installer would automatically configure a virtual directory and the default one http://localhost/tsweb/ would open up a page with an RDPClient ActiveX Control which emulates the behavior of the Client Application.


Now comes the catch. This one being on the webpage, does not have the abilities of saving details onto some desktop or somewhere. Is’nt it? I was having this issue and figured out an easy way. To write a small URL page redirecting to default.htm with all necessary information as URL QueryStrings. I then added a simple window.onLoad JavaScript to default.htm to parse the QueryStrings and launch the connection automatically. The only limitation is that you need to enter the password alone in the window that opens. At the moment, this solution is not able to attack passwords nor do I want to pass passwords in plain querystrings and store them unencrypted in desktop Internet Shortcut files.


The following steps can get you ready with this Remote Desktop Web Connection extension with JavaScript.


  1. Create a URL shortcut file with the URL having the following value: http://localhost/tsweb/Default.htm?srv=deepak&res=0&ac=Y&uN=lavanyadeepak&dN=deepaknetwork
    1. srv -> ServerName to connect
    2. res -> Default Resolution [0 FullScreen]
    3. ac ->  Autoconnect (Y)
    4. uN -> userName
    5. dN -> domainName
  2. Now open tsWeb/default.htm in your notepad and append the following script at the end of the page, preferably before the closing body tag:

<script language=”JavaScript”>
   function AutoStart()
   {
      if (self.location.href.indexOf(“?”) > -1)
      {
          var strQueryString = self.location.href.substring(self.location.href.indexOf(“?”)+1);
   
         var arrQueryStringsParts = strQueryString.split(“&”);
         for (var intCount=0;intCount < arrQueryStringsParts.length;intCount++)
         {
             var qryPart = arrQueryStringsParts[intCount].split(“=”);
             switch (qryPart[0])
             {
                case “srv”:
                          document.getElementById(“editServer”).value = qryPart[1];
                          break;
                case “res”:
                          for (var intOptCount=0;intOptCount<document.getElementById(“comboRes”).options.length;intOptCount++)
                          {
                             if (document.getElementById(“comboRes”).options[intOptCount].value == qryPart[1])
                             {
                                document.getElementById(“comboRes”).options.selectedIndex = intOptCount;
                                break;
                             }
                          }
                          if (document.getElementById(“comboRes”).options.selectedIndex < 0)
                            document.getElementById(“comboRes”).options.selectedIndex = 0;
                          break;
                case “ac”:
                          document.getElementById(“Check1″).checked = (qryPart[1]==”Y”);
                          if (document.getElementById(“Check1″).checked)
                          {
                             document.getElementById(“tableLogonInfo”).style.display = “block”;
                          }
                          break;
                case “uN”:
                          document.getElementById(“editUserName”).value = qryPart[1];
                          break;
                case “dN”:
                          document.getElementById(“editDomain”).value = qryPart[1];
                          break;
             }        
         }
        
         //If valid entries found, then connect…
         if (document.getElementById(“editServer”).value != “”)
            {
               document.getElementById(“connectbutton”).click();
            }
      }
   }
  
   window.onload = AutoStart;  
</script>


That configures your RemoteDeskop Web Connection page to relatively extend its features further.


/* Migrated from namespace LavanyaDeepak — posted on August 11, 2005 */

6 thoughts on “Automating Remote Desktop Web Connection”

  1. Hello,
    i need the code from default.html embed or use i some way in asp.net project.
    Could you help me with that ?

    I can use class MsRdpClient3Class from reference but how to add graphical interface to website ?

  2. This is a great addition and extremely usefull.

    I am maintaining a demo environment and used this now to log user during the demo quickly on. I would like to know if there is a way to extend the feature with a password case “pN”: part.

    Again great stuff!!

  3. Great code!! I’d like to ask you if it is also possible to set the value of the password to having a complete auto-connect directly to the server. I’d like to realize a complete automatic access to server without no login step include password. Thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>