0

How can I create a sub menu in windows right-click menu using the handlers? I already know how to create an action menu item, but im not clear on how to create a menu with this action item inside of it. In my case i'd like to create a submenu that is called John and have this action inside of it like the image shows.

To clarify: How do i create a subMenu called John and place my action inside of that menu?

static void create_menu()
{
    RegistryKey key;
    key = Registry.ClassesRoot.CreateSubKey(@"AllFileSystemObjects\shell\MyAction");
    key = Registry.ClassesRoot.CreateSubKey(@"AllFileSystemObjects\shell\MyAction\command");
    key.SetValue("", @"C:\Users\john\Desktop\simple.bat %1");
    key.Close();

}

enter image description here

JokerMartini
  • 5,674
  • 9
  • 83
  • 193
  • `key.SetValue("", @"C:\Users\john\Desktop\simple.bat %1");` should give you a clue. It opens the `simple.bat` file and passes the filename that was clicked on as the first parameter. Just change the `simple.bat` with your program and when it starts look at the arguments. – Ron Beyer May 14 '18 at 14:17
  • Possible duplicate of [Creating a submenu in the explorer-shell-extention?](https://stackoverflow.com/questions/11933326/creating-a-submenu-in-the-explorer-shell-extention) – BugFinder May 14 '18 at 14:19
  • @RonBeyer you completely mis-understood the question. I'm not looking to start an application. I'm asking how do i create a subMenu called John and place my action inside of that menu? – JokerMartini May 14 '18 at 14:30
  • @JokerMartini You can't "place an action inside it", Windows can run commands (programs/batch files) on context menu item clicks. All of the ones you see just open programs (except the cut/copy/things below). The only thing you can do is pass the file name to a command (program), you can't just attach raw code to a context menu item. Maybe it isn't clear what you mean by "place my action inside of that menu"? – Ron Beyer May 14 '18 at 14:33
  • You can't create submenus with registry hacks, a shell extension that implements IContextMenu is required. – Hans Passant May 14 '18 at 14:45
  • There is a rather large article series [on CodeProject](https://www.codeproject.com/Articles/512956/NET-Shell-Extensions-Shell-Context-Menus) about writing shell extensions, maybe that may be of help. – Ron Beyer May 14 '18 at 15:22

0 Answers0