3

How can I add menu items to the Context menu for folders? I don't want to do this via registry. I want to integrate this with my application's installer and when the application is installed, the context menu items should be added. On clicking the items, my application's method should be called (similar to what WinRAR does)

Thanks.

lostInTransit
  • 70,519
  • 61
  • 198
  • 274
  • I assume you mean the explorer context menu? – Marc Gravell Jan 02 '10 at 10:52
  • How about a paid for, pre-canned solution: http://www.contextmenu.net/ – Marc Gravell Jan 02 '10 at 10:53
  • yes @marc canned solution will be much better approach, otherwise it will be bit tough call! – TheVillageIdiot Jan 02 '10 at 10:55
  • Yes I mean the explorer context menu. But only want it to be visible when I right-click on a folder – lostInTransit Jan 02 '10 at 15:12
  • I understand writing shell extensions in managed code used to be notoriously unsafe (http://blogs.msdn.com/oldnewthing/archive/2006/12/18/1317290.aspx, http://www.codeproject.com/KB/shell/ratingcolumn.aspx). See also here: http://stackoverflow.com/questions/117651/how-can-i-create-my-custom-shell-context-handlers-for-windows, one user mentioned the problem was resolved but didn't give any reference so I would be cautious about this. Does anyone have an update on this issue? – RedGlyph Jan 03 '10 at 11:31

1 Answers1

2

There are two ways to add items to the context menu. I'm not sure why you don't want to use the registry, because it is the easiest method. And you can have your installer automatically add or remove the registry keys if you want. Both will use the registry anyway, since registering a Shell Extension involves adding registry keys.

Registry

This method is easy since it comes down to adding some registry keys. The downside is that you can't put any logic in it. You can read about it here. You get a bit more control if you are using DDE to execute the menu items. See here for a DDE example.

Shell Extension

This method is a bit more work, but you can completely control the context menu from code. You would have to write a DLL, implement IContextMenu (or others) and register the dll with Windows Explorer. You can read about it here and see here for an example. You could also check out 3rd party libraries like ContextMenu.

Lars Truijens
  • 42,837
  • 6
  • 126
  • 143