views:

134

answers:

4

I am a novice .Net 2.0 and 3.5 developer. I want to create an application that creates a context menu when a file is right clicked on in Vista. After the right click--I think I can figure out the rest, but I don't know the technique to get access to the Vista API.

FOLLOW-UP:

As I have been reading some of the info that folks have responded with, I have found that I am going overkill here with the shell extensions. I think I can keep this project a lot simpler if I just call my app and pass the filename as a parameter. This would still require my app to come up in explorer's context menu when files with certain extensions are right clicked on. How do I go about doing this?

A: 

The thing you are trying to write is called a "shell extension". I've never written one so I can't give you a quick example but now that you know what its called you can probably make more progress by searching for tutorials on Google.

Brian Ensink
A: 

I am fairly certain that you are not allowed to use managed code to write shell extensions for explorer in any version of Windows. So if you want to write one, you'll need to do it in a "traditional" language such as C++.

Colin Desmond
A: 

You need a Context Menu Shell Extension, now one thing to keep in mind is that you are not allowed to write them in .net (The old new thing blog).
You can try to write out-of-process extension (the skeleton is unmanaged which calls managed service thru IPC) but I didn't see anyone doning that.

Shay Erlichmen
+1  A: 

With the risk of sounding unhelpful, I'd recommend against this in .Net 2.0 or 3.5. As Brian said the thing you're trying to implement is a shell extension. These are implemented as libraries which the Vista shell loads.

While there are several tutorials around the web which give instructions on implementing these in .Net 2.0 or such few of these mention how bad idea this is. If you make the Vista shell load a .Net shell extension it is forced to load the whole .Net CLR which your shell extension requires. What makes this even worse is that you can load only one version of the full .Net CLR in one process. So if you have a shell extension that requires .Net 1.0 CLR and Vista has loaded this, it cannot load the 2.0 CLR your shell extension requires.

Also there are some Stack Overflow articles already discussing this.

Some information on implementing a shell extension in unmanaged C++ (KBCafe PDF, couldn't find a simple html link)

Mikko Rantanen