views:

342

answers:

3

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.)
+1  A: 

All you need to do is add some stuff to the registry. So yes you can do this with .NET 2.0. Here is an example of how to add Edit with Notepad.

%1 is the selected file if I remember right.

Petoj
This will NOT work under Vista and Win7. Only under XP and 2000. I dunno why.
Vasiliy Borovyak
I think the registry paths are different, but it should still work: http://www.vistax64.com/tutorials/89829-start-menu-customize-context-menu.html
Mark B
+1  A: 

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.

Mark B
http://www.codeproject.com/KB/cs/dateparser.aspx
alhambraeidos
+3  A: 

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.

DrPizza
The latest .Net 4.0 runtime supports in process side-by-side loading of the .Net 4.0 runtime (and ALL future runtimes) with earlier .Net runtimes.See following excerpt from http://msdn.microsoft.com/en-us/magazine/ee819091.aspx "With the ability to have multiple runtimes in process with any other runtime, we can now offer general support for writing managed shell extensions—even those that run in-process with arbitrary applications on the machine."
logicnp