Windows Shell Extensions in .NET

Wouldn't it be great if you could add your favorite tools right into the Windows Shell? And wouldn't it be great if you could do it from .NET? The good news is that you can! Shawn Wildermuth shows you how in this discussion of Windows Shell Extensions in .NET.

Like this article? We recommend

Like this article? We recommend

Like most of the developers out in the world, I have a bag of tools that I
have developed over the years. In the old days, these tools usually took the
form of command-line utilities to do a myriad of different tasks. As time wears
on, I spend less and less of my time at a command line. I still need these
tools, but it would be really useful if I could integrate them into the Windows
environment.

Understanding Shell Extension Handlers

The Windows Explorer is a wonderful little tool. It may look like just a
typical file/folder viewer, but it is actually a bit more simplistic than that:
The Windows Explorer is just an application that exposes the Windows Shell. The
view of the file system is called the Windows Shell. You will see the same
behavior all around Windows; file dialogs, Internet Explorer's FTP view,
and more.

Luckily for us, Microsoft has created a way to hook into the Shell to add our
own functionality. There are different types of Shell Extensions that we can
create. Some of the handlers are based on the type of file the user is looking
at (see Table 1).

Table 1. File-based Shell Extension Types

File Handlers

Description

Shortcut menu

Adds items to the popup menu for specific files
extensions.

Data handler

Handles data when Shell objects are dragged and dropped.

Drop handler

Makes a file become a drop target for a specific type of
file.

Icon handler

Allows overriding of the icon for types of files.

Property sheet

Allows you to add or replace pages in an object's
property sheet.

Thumbnail image

Allows you to specify the image to use for a thumbnail
image.

Infotip handler

Allows you to specify the text for the popup
infotip.

Metadata handler

Allows you to change or extend the metadata about specific file types.

Other extensions are based on the operation that the user is
attempting to do in the Shell, as shown in Table 2.

Table 2. Operation-based Handlers

Operation Handlers

Description

Column handler

Allows you to add or replace columns displayed in the details
view of a folder.

Copy hook

Allows you to intercept a copy operation to do specific
operations.

Drag-and-drop

Allows you to modify the drag-n-drop popup menu.

Icon overlay

Allows you to specify an overlay for icons.

Search handler

Allows you to implement specific search types.

For this article, we will create a simple Shortcut Menu
Handler. The handler will show up only when the user opens a folder's popup
menu, as shown in Figure 1.