Introduction
For the last few months, I've been working hard on the SharpShell project. This is a project that lets you quickly build Windows Shell Extensions using the .NET Framework. One difficulty that users were facing is that to deploy a Shell Extension written in .NET, you had to use the regasm tool, which would only be installed generally on development machines.
With SharpShell 2.0, there is a Server Registration Manager tool that makes deploying SharpShell servers a piece of cake.
The Series
This article is part of the series '.NET Shell Extensions', which includes:
- .NET Shell Extensions - Shell Context Menus
- .NET Shell Extensions - Shell Icon Handlers
- .NET Shell Extensions - Shell Info Tip Handlers
- .NET Shell Extensions - Shell Drop Handlers
- .NET Shell Extensions - Shell Preview Handlers
- .NET Shell Extensions - Shell Icon Overlay Handlers
- .NET Shell Extensions - Shell Thumbnail Handlers
- .NET Shell Extensions - Shell Property Sheets
- .NET Shell Extensions - Deploying SharpShell Servers
What is SharpShell?
SharpShell
is a very lightweight class library that lets you build Windows Shell Extensions using the .NET Framework. As you can see from the links above, there are lots of different types of servers that are supported. You can find a good introduction on the GitHub page, as well as examples of each type of server:
Deploying Shell Extensions
Deploying Shell Extensions written in C or C++ is generally straightforward, as the regsvr32 tool which is included in Windows can be used. However, to deploy a managed Shell Extension, the regasm tool must be used, which is not included by default on Windows. I have added the 'Server Registration Manager' tool (srm.exe) to SharpShell which makes it easy to install and uninstall servers.
Installing Servers from the Command Line
Download the SharpShell Tools binaries from this article, or get the latest from github.com/dwmkerr/sharpshell. Using this tool, you can install servers like this:
srm install server.dll -codebase
Easy! You can uninstall the same server like this:
srm uninstall server.dll
This is the key take-home from this article. The srm tool can install and uninstall servers - all other mechanisms (such as Windows Installers) will simply use this under the hood.
Creating an Installer for SharpShell Servers
In this example, I'll use Visual Studio 2010 to create an installer for the 'Count Lines' extension that was written in the first article.
Tip: You can also use WiX - just create a custom action to run the commands shown above!
Step 1: Create the Installer Project
Create a new 'Setup and Deployment' project from Visual Studio 2010. Now add your SharpShell server and the srm.exe tool to the application folder, like so:
Step 2: Add Custom Actions to Install and Uninstall
Now navigate to the 'Custom Actions' section of the installer. Create a new 'Install' custom action that executes the srm.exe tool from the application folder:
You can click on this action to set the properties. We'll need to pass the arguments 'install
', the path to the server, and the '-codebase
' flag (telling to install the server directly, not using a reference to the GAC).
Make sure that the 'InstallerClass
' property is set to False
, otherwise the installer will try and load an Installer Class object from the EXE, which it doesn't contain.
Now create a similar action for Uninstall
- this time, we need the 'uninstall
' command on the commandline, the server path as before, and no -codebase
flag. This is the command line I use in this example:
uninstall "[TARGETDIR]\CountLinesExtension.dll"
That's it! You can now run your installer to install the SharpShell server!
Final Thoughts
This is a very short and sweet article, but many users who have been working with SharpShell have been requesting an easier way to deploy their servers, so here it is!
History
- 15th September, 2013: Initial version