How add context menu item to Windows Explorer for folders

I have found out how to add right-click context menu items to files on Windows Explorer, by adding keys to the registry. Ie I can right-click on a file in Explorer and run a custom app against that file.

I would like to do the same for a folder and have not found a way to do that (yet). I see articles on creating/writing custom context menu handlers, but I would rather not go there.

I have found an article here on how to add cascading context menu items to the Desktop and to the "Computer" in Explorer, but this does not work for any folder.

I would like to be able to add my custom app to the context menu and have it work on both files and folders. Is there a way to do this without writing a context menu handler?


Context menu for right click on folders in left panel of Windows Explorer or on background of a directory in right panel:

  • HKEY_CLASSES_ROOTDirectoryBackgroundshell if you are administrator
  • HKEY_CURRENT_USERSoftwareClassesdirectoryBackgroundshell if you are a normal user

  • Context menu for right click on folders in right panel of Windows Explorer:

  • HKEY_CLASSES_ROOTDirectoryshell if you are administrator
  • HKEY_CURRENT_USERSoftwareClassesdirectoryshell if you are a normal user

  • Context menu for any file:

  • HKEY_CLASSES_ROOT*shell if you are administrator
  • HKEY_CURRENT_USERSoftwareClasses*shell if you are a normal user
  • In all cases:

  • add a new key under "shell", naming it as you want to name the context menu item
  • add a new key inside this key, named command (mandatory name)
  • edit the "default" property in "command" to myprogrampathpathpathexecutable.exe %1 to pass the file path and name of the selected file to your custom program

  • More customization:

  • Add icon : adds a string value named icon for key created at step 1 with value matching an icon resource path. You can also provide an integer arguments to specify which icon to use. Example: %SystemRoot%System32shell32.dll,3
  • Display only on shift-click : adds an empty string value named Extended for key created at step 1
  • Customize menu entry label : change the value of default value for key created at step 1
  • Change menu entry location : adds a string value named Position with one of: Top , Bottom

  • I found the solution in the below article, which describes how to do this via the registry for files, as well as for folders:

  • How to Add Any Application Shortcut to Windows Explorer's Context Menu
  • The following two articles provided additional info and options:

  • Ultimate Tutorial to Customize Desktop Context Menu in Windows Vista, 7 and 8
  • Add Cascading Menus for Your Favorite Programs in Windows 7 Desktop and My Computer Context Menus

  • I went back and also answered this in another topic since there doesn't appear to be much on this question specifically.

    I found the simplest way was to add a String Value to the key called "AppliesTo" and set its value to "under:{path}"

    In my example, I want it to only look in the T Drive, so my String value is "AppliesTo":"under:T:".

    In C#, this is easily accomplished with the following:

    RegistryKey _key = Registry.ClassesRoot.OpenSubKey("FolderShell", true);
    RegistryKey newkey = _key.CreateSubKey("My Menu Item");
    newkey.SetValue("AppliesTo", "under:T:");
    
    RegistryKey subNewkey = newkey.CreateSubKey("Command");
    subNewkey.SetValue("", "C:yourApplication.exe");
    subNewkey.Close();
    
    newkey.Close();
    _key.Close();
    
    链接地址: http://www.djcxy.com/p/57386.html

    上一篇: 如何打开任何窗口的上下文菜单?

    下一篇: 如何将上下文菜单项添加到Windows资源管理器的文件夹