Click here to Skip to main content
15,868,141 members
Articles / Desktop Programming / Win32

.NET Shell Extensions - Deploying SharpShell Servers

Rate me:
Please Sign up or sign in to vote.
4.98/5 (16 votes)
15 Sep 2013CPOL3 min read 87.1K   2.3K   27   33
Learn how to deploy SharpShell servers easily with the new Server Registration Manager tool

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:

  1. .NET Shell Extensions - Shell Context Menus
  2. .NET Shell Extensions - Shell Icon Handlers
  3. .NET Shell Extensions - Shell Info Tip Handlers
  4. .NET Shell Extensions - Shell Drop Handlers
  5. .NET Shell Extensions - Shell Preview Handlers
  6. .NET Shell Extensions - Shell Icon Overlay Handlers
  7. .NET Shell Extensions - Shell Thumbnail Handlers
  8. .NET Shell Extensions - Shell Property Sheets
  9. .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:

C++
srm install server.dll -codebase 

Easy! You can uninstall the same server like this:

C++
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:

Image 1

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:

Image 2

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).

Image 3

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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United Kingdom United Kingdom
Follow my blog at www.dwmkerr.com and find out about my charity at www.childrenshomesnepal.org.

Comments and Discussions

 
QuestionSetup leaves the DLLs behind after uninstall. Pin
Ruturaaj V. Patki6-Mar-18 6:20
Ruturaaj V. Patki6-Mar-18 6:20 
This Lib is excellent and I could write my first Shell Menu Extension in just a few min! However, I'm facing one problem... I am using Innosetup to build the Setup file and added the "uninstall" command for srm.exe which runs just before the Uninstaller starts removing components. Everything works smooth, except one thing. Setup fails to delete the DLL files. The my Shell Server DLL and SharpShell DLLs are left behind.

I understand this is due to the fact that these DLLs are locked by Explorer.exe process. However, I want to achieve a clean uninstall.

I attempted "taskkill explorer.exe" and then "start explorer.exe" to run just after "uninstall" command for srm.exe; it kills the process and so uninstaller manages to remove the DLLs; but the start of explorer process fails. This is worst! Big Grin | :-D

What is the best practice to implement the Uninstaller using any Setup Maker application of your choice?

Happy Coding !
AnswerRe: Setup leaves the DLLs behind after uninstall. Pin
Ruturaaj V. Patki10-Mar-18 2:39
Ruturaaj V. Patki10-Mar-18 2:39 
Questionhow to register sharpshell using regasm. Pin
Sourabh111129-Mar-17 21:14
Sourabh111129-Mar-17 21:14 
BugRe: how to register sharpshell using regasm. Pin
Ross Holder27-Oct-17 11:17
Ross Holder27-Oct-17 11:17 
AnswerRe: how to register sharpshell using regasm. Pin
Dave Kerr18-Oct-18 3:59
mentorDave Kerr18-Oct-18 3:59 
QuestionIssues while deploying Pin
midhun sankar4-Aug-16 11:53
midhun sankar4-Aug-16 11:53 
Questionruntime Error when installing a Server Pin
Member 1168474312-May-15 5:33
Member 1168474312-May-15 5:33 
AnswerRe: runtime Error when installing a Server Pin
Dave Kerr18-Oct-18 3:55
mentorDave Kerr18-Oct-18 3:55 
QuestionTroubleshooting deployment on End-User environment Pin
Diego Stamigni17-Apr-15 5:28
Diego Stamigni17-Apr-15 5:28 
AnswerRe: Troubleshooting deployment on End-User environment Pin
Dave Kerr18-Oct-18 3:55
mentorDave Kerr18-Oct-18 3:55 
Questionhow extension registration could be done in End-User Computer? Pin
mn_acer117-Mar-15 11:30
mn_acer117-Mar-15 11:30 
QuestionRestarting the Explorer Pin
Zeveloper2-Oct-14 9:01
Zeveloper2-Oct-14 9:01 
AnswerRe: Restarting the Explorer Pin
Dave Kerr13-Oct-14 20:59
mentorDave Kerr13-Oct-14 20:59 
GeneralRe: Restarting the Explorer Pin
tmag9-Apr-22 19:25
tmag9-Apr-22 19:25 
QuestionInstallshield Limited Edition Pin
RoRusten24-Sep-14 22:29
professionalRoRusten24-Sep-14 22:29 
AnswerRe: Installshield Limited Edition Pin
Dave Kerr30-Sep-14 17:33
mentorDave Kerr30-Sep-14 17:33 
AnswerRe: Installshield Limited Edition Pin
Stocklone4-Jan-17 5:46
Stocklone4-Jan-17 5:46 
AnswerRe: Installshield Limited Edition Pin
Stocklone4-Jan-17 5:46
Stocklone4-Jan-17 5:46 
GeneralThank you! Pin
JulienV10-Mar-14 21:57
JulienV10-Mar-14 21:57 
GeneralRe: Thank you! Pin
Dave Kerr11-Mar-14 5:52
mentorDave Kerr11-Mar-14 5:52 
Questionsrm.exe crashing when registering example DLLs Pin
AlexanderPD8-Jan-14 0:51
AlexanderPD8-Jan-14 0:51 
AnswerRe: srm.exe crashing when registering example DLLs Pin
Dave Kerr17-Jan-14 21:18
mentorDave Kerr17-Jan-14 21:18 
GeneralRe: srm.exe crashing when registering example DLLs Pin
bkaratte26-Jan-15 14:13
bkaratte26-Jan-15 14:13 
GeneralRe: srm.exe crashing when registering example DLLs Pin
Dave Kerr1-Feb-15 20:37
mentorDave Kerr1-Feb-15 20:37 
QuestionProcess cannot access the file Pin
Marla Sukesh25-Oct-13 18:42
professional Marla Sukesh25-Oct-13 18:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.