Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrating into Windows Explorer context menu

I want to write a small tool, that does the following:

When you right click on a file with a certain file-extension the Windows Explorer context menu shows an additional entry.

When you click this entry a certain EXE is launched with this file as one of its parameters.

I would like to use C#/.NET 2.0 for this. If it's not possible I could also do it with C++/Win32.

My questions are:

  1. Is it possible with C# .NET 2.0?
  2. What are the necessary functions for integrating into the Windows Explorer context menu?
  3. How can I make this permanent? (I don't want to relaunch this tool after every boot)
  4. What do I have to take special care of? (different OS, security permissions, etc.)
like image 931
clamp Avatar asked Dec 03 '09 09:12

clamp


People also ask

What is Explorer context menu integration?

The Right Click Menu or the Context Menu is the menu, which appears when you right-click on the desktop or a file or folder in Windows. This menu gives you added functionality by offering you actions you can take with the item.

How do I add programs to the Explorer context menu?

Add Any Program to Context Menu. Open the registry and navigate to the following path: HKEY_CLASSES_ROOT\Directory\Background\shell then right-click on shell and select New > Key. Give the new key the name of the program you're adding to the context menu. I'm going to add Internet Explorer for this example.

How do I add programs to the context menu in Windows 10?

Adding Applications to the Desktop Context MenuRight-click on the “shell” key, and then choose New > Key from the menu. Give the new key the name that you want to show up on the desktop context menu.


2 Answers

You will need to access the registry and add a key under root\\File\\shell or root\Folder\\shell, depending on which items you want the menu item visible on.

Try this article at CodeProject, it's quite useful.

Edit: There's another article here which may be of help.

like image 94
Mark Bell Avatar answered Oct 09 '22 03:10

Mark Bell


It is, incidentally, not supported to use .NET for shell extensions, due to the current inability to host multiple runtime versions in the same process (.NET 4 will lift this restriction).

Consider the case where you have two shell extensions; one for .NET 3.5, one for .NET 1. Which runtime will get loaded into your process? Well, it's more or less random--it depends which shell extension gets loaded first. Sometimes it might be the 2.0 runtime, sometimes it might be the 1.1 runtime.

This is also an issue if a .NET program creates common file dialogs; your shell extension may or may not load, and may or may not run with the correct runtime version.

As such, if you go down the Shell extension route you should use native C++/COM/Win32.

like image 31
DrPizza Avatar answered Oct 09 '22 02:10

DrPizza