Click here to Skip to main content
13,141,576 members (52,554 online)
Click here to Skip to main content
Add your own
alternative version


12 bookmarked
Posted 22 Jan 2015

Cinchoo - Simplified Shell Context Menu Extensions development

, 22 Jan 2015
Rate this:
Please Sign up or sign in to vote.
Simple and easy to create, self installable and use Shell Context Menu Extensions.

1. Introduction

Cinchoo is the application framework for .NET. One of the main functionalities it provides to the users is application configuration management. It offers rich base framework classes to build .NET applications targeted on Windows platform. 

In this article, I'm going to illustrate how to extend the Windows shell via context menu using Cinchoo library. These context menus must be for a specific file type, such as *.pdf files, drives, folders and more. This provides a way to customize Windows shell functionality through Windows Explorer. It is a simpler, fluent model for developing shell extension context menus rapidly. Making it as library letting you to concentrate yourself on the core development tasks.

2. Requirement

This funcionality is written in C# for the .NET 4.0 Framework. It is part of Cinchoo framework, which is a great library with lot of features like Configuration Management, common ApplicationHost, Shell features etc.

3. "Hello World!" Sample

Lets begin by looking into a simple example of an creating shell extension application with 'Hello World' context menu attached to any file (*) type.

Figure 3.1 Screenshot of 'Hello World' shell context menu

  • Download the latest Cinchoo binary here. (Nuget Command: Install-Package Cinchoo)
  • Open VS.NET 2010 or higher
  • Create a sample VS.NET (.NET Framework 4) WinForm/Console Application project
  • Add reference to Cinchoo.Core.dll
  • Use the Cinchoo.Core.Shell namespace
  • Copy and paste the below Shell Extension object

Listing 3.1 Defining Shell Extension Object

public class HelloWorldShellExt
    public static void HelloWorld(string[] args)

The code above illustrates about defining shell extension object. First thing define a shell extension class (ex. HelloWorldShellExt) and it must be decorated with ChoShellExtensionAttribute to complete the definition. Define a context menu method (ex. HelloWorld) decorated with ChoShellExtensionContextMenuAttribute. In this sample, this method is defined to be called for any file type (*). When a user right click on a file in the Windows Explorer and clicked the 'Hello World' context menu, this method will be called with the referenced filepath.

Next define a application host object as below,

Listing 3.2 Application host object

public class AppHost : ChoApplicationHost

The purpose of this class is to enable your application self-installable shell extension program. The above code illustrates about defining one.

Finally, lets write the main entry code as below

Listing 3.3 Main Method

class Program
    static void Main(string[] args)

Thats all, your application is now ready to be installable as shell extension and called by Shell when context menu is clicked.

Listing 3.4 HelloWorld.exe with /#SE:Register

>HelloWorld.exe /#SE:Register

The above command line argument lets you register your application to the shell.

Listing 3.5 HelloWorld.exe with /#SE:Unregister

>HelloWorld.exe /#SE:Unregister

To unregister the application, pass /#SE:Unregister command line argument to the application.

4. Defining Shell Extension Object

4.1 Attributes

4.1.1 ChoShellExtension

This attribute is applied to the class containing shell extension context menu methods. This class will be discovered by Cinchoo framework during installation, invocation of shell extension methods.

4.1.2 ChoShellExtensionContextMenu

This attribute can be applied to the methods of the shell extension class to designate them as shell extension methods. This attribute designate the methods to receive the command when the user clicks on the context menu from Windows explorer. You can define multiple shell extension handler methods using this attribute for any file types. FileType

Specify file type, such as *.txt files, file classes such as 'text files', folders, drives etc. to which the context menu handlers will be registered to. MenuText

Specifies the context menu text. It is optional. If not specified, method name will be used as context menu text. Icon

Specifies the context menu icon. It is optional. If not specified, application icon will be used. IconIndex

If your application executable contains multiple icons, you can use one of them for context menu by specifing the icon index. There is no straight approach to add multiple icons to .NET application. But the below article explains the steps to add some ShellKeyName

Specify the registry key name. It is optional. If not specified, method name will be used as shell key name.  AdditionalCommandLineArgs

Specify any additional context information required to process the request. It is optional. Framework automatically remembers and pass these information to the handler.

5. Installing Shell Extension Object

5.1 Self-Installable

If your application build using Cinchoo framework application host, your application is self-installable. Make sure to run the application in Administrator privilage mode in order to register it successfully.

First define a application host object as below

Listing 5.1 Application host object

public class AppHost : ChoApplicationHost

The purpose of this class is to enable your application as self-installable shell extension program. Then write the main entry code as below to complete the application as self-installable program.

Listing 5.2 Main Method

class Program
    static void Main(string[] args)

5.2 Custom Installation

Some cases you may want to control and customize the installation of Shell Extension objects. This section will talk about the commands available to accomblish the installation of shell extension objects.

Cinchoo exposes methods via ChoShellExtension class to discover, register and unregister shell extension objects.

5.2.1 Register

This method used to discover all the shell extension objects available in your application and register them with the shell.

5.2.2 Unregister

This method used to unregister all the registered shell extension handlers.



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


About the Author

United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionIs it possible to completely replace the windows shell context menu with a custom menu? Pin
josegonzales90926-Feb-15 23:03
memberjosegonzales90926-Feb-15 23:03 
AnswerRe: Is it possible to completely replace the windows shell context menu with a custom menu? Pin
Cinchoo27-Feb-15 4:29
memberCinchoo27-Feb-15 4:29 
QuestionFull Trace Pin
Janak Desai26-Jan-15 8:39
memberJanak Desai26-Jan-15 8:39 
AnswerRe: Full Trace Pin
Cinchoo26-Jan-15 8:58
memberCinchoo26-Jan-15 8:58 
QuestionException Pin
Janak Desai26-Jan-15 8:33
memberJanak Desai26-Jan-15 8:33 
AnswerRe: Exception Pin
Cinchoo26-Jan-15 8:37
memberCinchoo26-Jan-15 8:37 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.170915.1 | Last Updated 22 Jan 2015
Article Copyright 2015 by Cinchoo
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid