LavanyaDeepak 2.0

My discoveries with .NET Framework and Windows, tidbits, codesnippets.
Embedded Object treated as an image

Embedded Object treated as an image

I just wanted to share a little personal experience with Microsoft Word. I have my personal word document which contains an embedded zip object containing my Todolist files. I keep it as a single capsule for portabiity reasons. I just have one observation that when the object is copied using Word's clipboard operations and pasted to Explorer and even after that closing the Word document you would be getting a message like 'You placed a large image in the clipboard'.

I admit that binary objects are images from the DEV perspective but just thought Word should be more explanatory in the nature of the message when it comes to addressing and clearing the doubts of a non-tech-savvy person.

This applies to Microsoft Word 2003.

Invisible Textboxes with FireFox

Invisible Textboxes with FireFox

Today morning, as my FireFox requested an upgrade to the newer version and I religiously clicked yes. When it completed the update, it wanted to restart itself and I adhered to its order too. But after restart interestingly, some of my most commonly used websites presented their login pages with invisible textboxes. But when click somewhere in the context, it could recognize the textbox element.

Posted: Sun, Oct 11 2009 4:59 by deepak | with no comments
Filed under: ,
An amazing persistence ability of session of FireFox to Task Manager End Process

An amazing persistence ability of session of FireFox to Task Manager End Process

Today morning my system behaved little weird. I am trying to be little optimistic. The good old system with its meagre resources on RAM had been that way for long though anyway. But that is another story. :) The FireFox was getting too much of memory and after a good deal of haggling and bargaining for well over five minutes, I chose to outsource the deal of paying tribute to the process life of FireFox.

When I restarted FireFox, I was amazed to see the following message like 'FireFox session was killed and if I wanted to restore session'. Task Manager warned me before end process that sessions would be destroyed without any chance of resurrection but interestingly,  FireFox offered me to help restore damaged and sabotaged sessions.

This is one good example that we should also try getting into our applications like persisting data so that the user can be spared for his hard word in case of catastrophic failures.

DOM Inspector Tool in FireFox

DOM Inspector Tool in FireFox

Those of you developing extensive JavaScript or UI based web-based applications would have encountered and spent most of the time in creating alert to see if a div exists and document.getElementById (width) etc.

Just was trying out FireFox (same as Netscape family, I hope).

It has a real cool tool embedded called DOMInspector, which aides in inspecting the DOM Structure of the URL that is being viewed.

Check out FireFox at: http://www.mozilla.org/products/firefox/ 

/* Migrated from Daffodilnet Express -- posted on December 3, 2005 */

Working with System.Web.Mail namespace...

Working with System.Web.Mail namespace...

We use System.Web.Mail namespace to send emails from our .NET Applications. It uses two main classes called MailMessage and SmtpServer. The latter having a single static property to indicate the email server (smtp host) to use and a public method taking an instance of MailMessage carrying the mail to be delivered.

Internally it is supposed to be a wrapper on the CDO Object and lot of P/Invoke stuff being builtin, the exception stack too can be significantly larger. Quite interestingly, there is one website called http://www.systemwebmail.com/ which I would like to share with the readers which discusses at length, System.Web.Mail namespace, FAQ etc.

/* Migrated from Daffodilnet Express -- posted on 11th December 2005 */

Managing Remote Terminal Sessions -- The Easy Way

Managing Remote Terminal Sessions -- The Easy Way

Windows 2000 brought in an elegant way of working on remote desktops by the concept of Terminal Services. But it was an additional Windows component that needed to be installed and configured, which meant additional license costs and administerial functions to setup and followup. However, it did gain in a perspective that the dependency on a third party application be it commercialware (like pcAnywhere etc) or an opensource (VNC, RealVNC etc) was broken down.

Windows XP took this one step ahead with the concept of Remote Desktop by way of RDP protocol. However, it allowed only one user to work on the system, transferring the control appropriately.

I have been using Windows 2000 Terminal Services for a long long time and one daunting and nightmarish problem that I had to face is that to ensure that users logoff rather than disconnect. When you disconnect a session, Windows Terminal Services remembers this and prevents any new users from opening a connection unless the free sessions are available. The default session count, I guess, is 2 for Windows Terminal Services.

Last week, while casually surfing the web, I came across two nice tools to manage this scenario:

  1. qwinsta.exe:  Displays information about Terminal Sessions
  2. rwinsta.exe: Resets the session subsystem hardware and software to default values. Effectively, you can use this tool to reset disconnected users so that other users can login.

From a developer's perspective, I feel, that we can have a simple Windows Form application in C# to manage these. Perhaps this weekend, I would try to get a small application and publish it over my personal website for other readers' use.

From C#, we just need to use WTSAPI32.dll using DllImport to manage the functionalities of QWInsta and RWInsta. More information about this tool over here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/termserv/termserv/run_time_linking_to_wtsapi32_dll.asp

/* Migrated from Daffodilnet Express -- posted on January 1, 2006 */

Developing Applications for the Web is a breeze with Internet Explorer Developer Toolbar...

Developing Applications for the Web is a breeze with Internet Explorer Developer Toolbar...

Debugging a web application, particularly its HTML counterpart like image path, Stylesheet, Scripting and design template issues has always been a nightmare for web developers and this always never fails to spark off arguments between the designers of the team, who would be stubborn for look and feel and developers reluctant to apply apprehending the implementation difficulties and browser compatibility issues.

There had been little tools to this perspective from various vendors like DOMInspector from Mozilla FireFox, MyIE2 had its own Scripting Inspector.

Now you can check out an Internet Explorer Developer Toolbar from Microsoft, which is available from this URL: http://www.microsoft.com/downloads/details.aspx?FamilyID=e59c3964-672d-4511-bb3e-2d5e1db91038&displaylang=en.

However,  please take note of the following:

  1. The Toolbar is still in BETA stage.
  2. The Toolbar gets installed only if IE 6 is installed.

/* Migrated from Daffodilnet Express -- posted on February 22, 2006 */

Clearing IE Cache

Clearing IE Cache

Cache -- the five letter buzz word remains as a double-edged sword. System Administrators and Network Administrators appreciate it and recommend it for simple reason, that network bandwidth is conserved. Developers, to an extent blame it since sometimes Old data crops up.

There has been a lot of programmatic options we stipulate from our webpages to clear cache like Pragma, Cache-Control directives.

Here comes one solution from Microsoft called ClearCache. Check it out at: http://www.microsoft.com/downloads/details.aspx?familyid=5CBD4659-3B28-4801-8729-05335902CE79&displaylang=en

/* Migrated from Daffodilnet Express -- posted on February 2, 2006 */

Access to the path containing 'hash.web' is getting denied.

 

Access to the path containing 'hash.web' is getting denied.

After installing Visual Studio .NET and F5 a couple of times, I used to get this error frequently. The only resolution was to wait for upto 5 to10 mins or restart system, since a folder in Temporary ASP.NET files containing web.config gets locked up automatically.

After searching a while in KBs, Forums, I found one closest matching solution, which solved my problem. Just wanted to share with other readers who would also be experiencing this issue. The problem occurs significantly if you touch web.config and ASP.NET has significant memory consumption (as seen in Windows Task Manager)

There is a service called Indexing Service which runs in the system. During F5, ASP.NET tries to JIT compile the new dll (as my understanding goes) and when simultaneously ASP.NET and Indexing service goes to the specified set of cache files, the deadlock occurs and ASP.NET throws this exception.

Solutions:

  • Keep Indexing Service Manual or Stop It
  • In Indexing Service Preferences, Make C:/Winnt/Microsoft.NET to be excluded or placed in the exclusion catalog so that Indexing Service will not access this location.

/* Migrated from Daffodilnet Express -- posted on October 15, 2004 */

Time Synchronizations in Windows

Time Synchronizations in Windows

Recently one of my components that I was developing was DateTime driven and hence I had to change system time to see its behavior for different periods. The problem is that, you need to be very careful with changed system times, particularly when you checkin the file to SourceSafe, SendMails since a wrong time means total chaos for these systems.

For these, I choose to have a simple batch file to syncrhonize time with the SourceSafe database itself. It just goes like this:

net time \\mysourcesafeserver  /set /y

net time \\mysourcesafeserver queries the time on the server
/set sets the time on the localhost to the time on the server (This will wait for a prompt of confirmation from the user, which can be avoided by appending a /y to the command)

But I have a question. Perhaps if some sysadmin drops by this post, he can put a comment and solve this so that it will be useful to other readers.

  1. What happens if the logged on user does not have privileges to set time? He is getting Access is denied.
  2. With Windows XP (Time Synchryonization) itself, will the problem in (1) get solved?
  3. To query net time \\mysourcesafeserver one must be logged on to \\mysourcesafeserver previously either my remembered network connection or previous manual logon? Is there any other solution for this?

But I hope the above batch file would be useful to many developers playing with and developing DateTime driven components.

/* Migrated from Daffodilnet Express -- posted on October 15, 2004 */

Quick Shortcut to Lock Workstation

Quick Shortcut to Lock Workstation

We normally use QuickLaunch bar in System Taskbar for almost any of our tasks. When we want go away from our system, we normally lock the workstation. Just a curious tip. A simple two three lines of code in C# can place a nice application whose shortcut can be placed in QuickLaunch bar to Lock the Workstation.

Console Version

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace QuickLock
{

       class MyComputerLock
      {
            [DllImport("user32.dll")]
            public static extern void LockWorkStation();

             static void Main(String[] args)
            {
                     try
                          {
                                 LockWorkStation();
                          }
                          catch (Exception ee)
                         {
                               MessageBox.Show(ee.Message);
                          }
              }
       }
}

Alternatively,if you put the code in Windows Form and you can customize the App.ICO to some friendly ICO file which will showup in QuickLaunch bar instead of the old rectangle which shows up for an EXE.

/* Migrated from Daffodilnet Express -- posted on October 15, 2004 */

Protecting EmailAddresses on Websites

 Protecting EmailAddresses on Websites

Email addresses like a@b.com (and these patterns)  are sure to invite spammers to get your addresses on to their spam databases. Just found out the following URL, which will help you to protect your email address from being spammed.

http://automaticlabs.com/products/enkoder 

/* Migrated from Daffodilnet Express -- posted on October 14, 2004 */

ConnectionString Manager

ConnectionString Manager

Most of us, who are using multiple SQLServer connections from our applications need to remember the connectionstring to be replaced in web.config to test the application with the different SQLServers. Either each and every time, we need to type the connectionstring parts. I just thought, I could start out writing a simple web application which could create the connectionstring from the Microsoft-provided DataLinks tool and then it can save the connectiongstring to a text file with a specific extension like .scn (Saved Connection Strings). Currently it saves one connectionstring per file, since I felt that would be easy. The other flexible options could be save all bunch in an XML file or as an Registry Entry.

Currently I have included the following basic options in the utility:

  1. Creates a new connection string, sets the item in the system clipboard and prompts to save it to a location.
  2. Edits an existing connection string , sets the item in the system clipboard and prompts to save it to a location.
  3. Double-clicking the .SCN file automatically launches the Edit action for the connectionstring and then the control flow resumes normally.

TODO:

  1. Optionally, keep all connectionstrings in Registry.
  2. As an addon, encrypt the connectionstring and save it, to enable secure saving of confidential database login credentials.

I would try to upload the utility tonight to my Daffodilnet workspace and then update the URL here.

/* Migrated from namespace LavanyaDeepak -- posted on September 13, 2005 */

PDF in .NET

PDF in .NET

A newer and a good utility assembly, which I found, which could manage and generate PDF documents on the fly with simple code in C# and .NET. Check out http://itextsharp.sourceforge.net/ . It just contains a simple DLL that need to referenced from your solution, which does all the magic.

/* Migrated from namespace LavanyaDeepak -- posted on November 2, 2005 */

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 */

Dr. IIS

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 

/* Migrated from namespace LavanyaDeepak -- posted on August 7, 2005 */

Automated EventLog Clearing and Backup Tool

Automated EventLog Clearing and Backup Tool

Developers writing Windows Services would normally heavily use Windows EventsLog to log messages from the application to System,Application, Security etc builtin logs or to custom log sources too. During development the amount of messages getting logged would be enormous and sometimes during development and testing, we normally and frequently right click clear individual logs before re-running the service again.

I just thought instead of repeatedly doing this, let us put a small Windows Application, enumerate all the available System Logs. The user has to simply run the application, select the logs he wants to clear, and hit clear button.

Out of my own interest, I wanted to get some feel of GUI tricks in Windows Forms like ProgressBar and have used some tricks like ThreadPool to update the parent thread to update it.  Tonight I would try to upload to DaffodilNet page at

http://www45.brinkster.com/daffodilnet/eventlogmanager.aspx

TODO:

There are lot of scope of improvement of this tool. Perhaps significant points to improve upon are:

  1. Backup target to EVT (EventLog Native File). I am trying to explore the feasibility with WMI Api in .NET like the ones in System.Management namespace.
  2. Security Checks. If a non-administrative user loads, then instead of attempting the thread and crashing it can proactively say 'Not all sections of the application are executable by the logged on user, since it needs additional administrative privileges'. Remember, when you run Disk Administrator in Control Panel -> Administrative Tools -> Computer Manager, you see this alert.
  3. Perhaps if you have some suggestion, do send me. I would try to incorporate it.

/* Migrated from namespace LavanyaDeepak -- posted on July 30, 2005 */

Dependency Walker

Dependency Walker

I was trying to figure out what are the dependencies for a OCX file which I was trying to package. Since I had only Visual Studio .NET in my system, I did'nt have a Dependency Walker (depends.exe).

A brief search in Google revealed this website http://www.dependencywalker.com/ which is the same tool that gets shipped with Visual Studio 6.0. I wanted to share this with my readers of the blog too for their use and reference.

/* Migrated from namespace LavanyaDeepak -- posted on July 29, 2005 */

Elegant Classification in Dropdown Boxes

Elegant Classification in Dropdown Boxes

Dropdown boxes are part of any common webpage. When there are more number of values, then it would be harder to read and would be very unfriendly to the user at large.

One of my friend was asking some trick to workaround this issue and I was suggesting him some XmlHttpRequest and other trick to load it in piecemeal fashion. And accidentally, I discovered a nice trick in HTML called OPTGROUP.

India Pakistan Turkey Australia New Zealand

The elegance of this structure is that the Label Captions are skipped by the web browser automatically and you can apply different coloring for the group.

/* Migrated from namespace LavanyaDeepak -- posted on June 30, 2005 */

QueryExpress -- Tool for Database Updates

QueryExpress -- Tool for Database Updates

A little neat tool from http://www.albahari.com/ which facilitates you to connect to SQLServer, Oracle or any OLEDB Compliant databases. Furthermore, it comes with its source code availability. Its salient features being Threading and Async QueryExecution, plain vanilla XML serializing of connection details and introducing developers to use TypedDataSet.

It was an interesting coincidence that I got to know of QueryExpress sometime about 3 years ago, when we were in  a small organization in Chennai executing a portfolio management project for a client based in California. The database was IBM DB2 and there were no friendly database connector tools and the then ignorance of us in DB2 made us very desparate and discouraging.

A brief search in Google revealed this nice tool. This has enthralled me so much. Even me, nowadays try to update the source, to keep it as a supreme product.

Here are the links to QueryExpress:

  1. QueryExpress home on http://www.albahari.com/ : http://www.albahari.com/query express.html
  2. QueryExpress with ODBC Support: http://www45.brinkster.com/daffodilnet/queryexpress.aspx

Do send us suggestions on what you would like to see in QueryExpress...

/* Migrated from namespace LavanyaDeepak -- posted on July 15, 2005 */

More Posts Next page »