August 2005 - Posts

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.

with 0 Comments

Dr. IIS -- Clear Cache, Restart IIS Processes etc.

Dr. IIS

Any developer using ASP.NET and VS.NET IDE would have experienced issues with Cache Folder of ASP.NET, VSWebCache having mismatched versions and hence breakpoint not getting hit. We normally use tricks like clearing it manually

This weekend, I was relatively free and thought I would get some practice on Windows Forms in .NET. I made a small application in Windows Forms and nicknamed it Dr. IIS.

I have tried addressing the following issues:

  • Recycle ASPNET Worker Process (currently it detects aspnet_wp as processname. We need to generalize it to w3wp for Windows 2003)
  • Restart W3SVC Service
  • Purges IDE Cache (VsWebCache)
    • Detects first any Visual Studio .NET instances are running. If yes, this option is disabled and a button appears to close existing Visual Studio Instances and then the checkbox gets enabled.
  • Purges Temporary ASP.NET Files from the default version of .NET Framework
  • Pause Indexing Service
  • Also checks whether the logged on user is Administrator. If the user does not have administrator privileges, then the application exits.

I understand that there are lot of scope of improvements to this. Perhaps my next TODO in this would be:

  • Generalize Detection of Worker Process (ASPNET for IIS 5.1 or lower and W3WP for IIS 6)
  • Threaded Application Model
  • CommandLine or Silent Mode
  • Detect and Customize the application to the configured .NET Framework (in case multiple versions exist)
  • Selectively add the required folders to Indexing Service Catalog for exclusion from Indexing.

I would keep updating it in my personal workspace and would publish the URL here. Please do send me your suggestions and improvements for the same.

The current download URL is http://www45.brinkster.com/daffodilnet/tools/driis.aspx 

with 3 Comments