简体   繁体   中英

How to add items with subitems to system context menu using C#

I want to add some new items (with subitems) of my software to context menu like this

So I looked in the registry and found this:

And I guess that the software "Google Drive" had created some owner classes (or service) to add command to its context menu, and the string {BB02B294-8425-42E5-983F-41A1FA970CD6} is the presentation of this service (or classes), like the Windows SendTo Service (Right click -> Send To)

But how to do that?

First of all the most important thing, there is no way to create nested context menus without context menu handlers .A context menu handler is nothing but a registered COM Server on the users computer.A COM Server exists in the form of a dynamic link library.To explain it better,let me take an example from your first image;The menu entry named Google Drive is a COM Server and entries Copy to Folder and Move to Folder are simple shortcut entries in the registry.Making shortcut entries with specific commands is relatively easy.
To make a shortcut at the desktop context menu for example to Launch Notepad ,locate the following registry key in registry editor, [HKEY_CLASSES_ROOT\\Directory\\Background\\shell] ,create a new key in it,name it Launch Notepad ,in its default value add this, Execute Notepad .Now create a new key under Launch Notepad and name it command and add this to its default value notepad.exe .That's it,now right click on your desktop you will notice a new entry named Execute Notepad ,clicking it will open Notepad.So that was the method to create a simple shortcut entry,please note that these shortcut entries cannot be nested means you cannot add any entry under Execute Notepad entry.

Now if you want to learn how to get started in making shell extensions,have a look here .
Hope this would have helped you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM