Ever since I got to know about existence of shell extension programming for Windows I always wanted to write one. The utilities provided by shell extensions is umpteen in Windows. However, being a C# developer has always limited me to get in to shell programming as its majorly based on C/Win32 programming. Moreover till .NET 4.0, writing shell extensions using managed code was not supported officially (MSDN).
However if you assume that there are readily available examples to start development right away you are wrong. There are hardly any examples and documentation is almost nil. However, while stumbling the web to find easier way to write shell extensions and of course using C# language, I found this great library called EZShellExtensions.NET
Writing shell extensions using EZShellExtensions is very easy. The advantage is that you can write using C# and right within Visual Studio. With this library you can write all kinds of shell extensions for windows. Some of my favorites are,
- Context menu handlers – Allows you to add new menus to file/folder context menu
- Property sheet extensions – Ability to add new tab on property windows of file/folder
- IE toolbars!
- and many more
Since, my upcoming shell extension is a context menu handler, my features below cover mostly that. For more examples on other types of shell extension I suggest you to refer author website.
Installation
Once you download and install the component, you will notice that it has installed many project templates to Visual Studio (supports all editions of Visual Studio from 2003 to VS2012!). Based on your requirement, you will have to chose the proper project type (context menu handler, property sheet etc) and after that you are ready to go. The code wizard generates is simple to read and it has lot of comments for each method to let you know what needs to be done.
Coding
One of the best part of ESShellExtensions is that it very easy to code because of its attribute style programming. For example, if you are writing a context menu handler for a particular file type (for ex: .dll) you just need to add following attribute to your class file.
[TargetExtension(".dll", true)]
Although, a default menu item is already added in the code generated by template, adding one more menu item is again by duplicating the code.
e.Menu.AddItem("New Menu Item", "new-item-name", "New menu item string");
Suppose you need to have a sub menu its easy too!
ShellMenuItem mainMenu = e.Menu.AddItem("Main menu", "main-menu", "Main menu desc");
mainMenu.HasSubMenu = true;
var mnuSub = mainMenu.SubMenu.AddItem("Sub menu", "sub-meu", "submenu desc");
EZShellExtension.NET also supports adding custom icons to menu items. Further, the selected file path can be easily received by TargetFiles[0]. It is that easy!.
Other hidden gems
Apart from being easy to use, EZShellExtensions.NET provides a many custom tools like RegisterExtensionDotNet.exefor easily registering shell extension and RestartExplorer.exe which are helpful to deploy extensions on user’s system. Both the tools are free to distribute with your installers and makes your life easy by saving lots of time in testing your installers for pre and post deployment actions.
Documentation
Although EZShellExtension.NET comes with more than 20 examples (both in C# and VB) and help file (which are enough to start with), my personal opinion is that component still needs a detailed documentation explaining individual properties, events and methods (along with examples to use them) for advanced users. I also feel the need of user forum to post questions and receive answers from other users of EZShellExtension.NET.
As you can see, I have only highlighted only one context menu extension development above but you can write lot other types of extensions with the same few lines of code. The component comes at 99$ for 1 developer license, which in my opinion is absolute worth.