0

I want to add a context menu option for deeper integration of one of my programs. However, I hate when I have 20+ items in this heavily used menu - so I wont make my end user endure this as well.

I know the context menu can be customized by file type, but Tortoisegit is able to customized generic folders.

Tortoisegit is some how able to detect when the context menu is opened in a folder controlled by Tortoisegit and display a different menu with additional items.

How is this done? Is this done by Tortoisegit somehow running in the background, or a registry setting for context menus, or something else?

Revious
  • 7,816
  • 31
  • 98
  • 147
Mark Lopez
  • 180
  • 3
  • 9

1 Answers1

1

It is done with a registry setting. Run regedit.exe and navigate to HKCR\Folder\shellex\ContextMenuHandlers. You'll find the CLSID for Tortoise in that list. The HKCR\* registry key is similarly special, it works for any file.

Writing shell extensions in C# is strongly discouraged, failure to inject the CLR into a process is undiagnosable.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Thank you, there seems to be a lot of Windows API's that should never be used in C#. Could you provide your source documentation for my and Stack Overflow's reference? Google can only find simple tutorials for the common user. – Mark Lopez Nov 04 '13 at 15:25
  • 3
    Using the winapi is just fine, no problems there. It is just that injecting managed code into other processes is troublesome. Shell extensions are just too impactful. Your code doesn't just get injected into Explorer, it gets injecting into *any* program that uses the shell dialogs, like OpenFileDialog. – Hans Passant Nov 04 '13 at 16:21
  • I found an article that .Net 4.0+ allows native injection of shell menu handlers. These can be debugged, but only within a sandboxed Visual Studio environment. – Mark Lopez Nov 04 '13 at 16:30
  • No, that already worked before. What's special about .NET 4.0+ is that it allows more than one version of the CLR to be loaded. But it is still a chicken-and-egg problem, if an old version of the CLR got loaded first then you still lose. Completely undiagnosable to the user and shell extension load order can't be tweaked. – Hans Passant Nov 06 '13 at 14:50