开发者

manipulate Windows explorer context menu

I am currently writi开发者_Python百科ng application with WPF in framework 3.5 SP1, and I need to extend my functionality to Windows Explorer context menu, like how Winzip or Winrar or anyone else did when user right click on a file or folder.

I did a lot of study, some said use Registry, which after I tried, is quite inflexible. Because I need sub menu in my context menu, and also icons.

Another approach I found, is the shell programming, which is even more nasty, but have much much more potential than the registry method.

Shell programming require COM programming knowledge, which need time to learn.

For all the articles I found about modifying windows explorer context menu, they are mostly published in year 2003, 2005 etc, it's 5 years ago, I mean, after 5 years of development, is there any new technology that can make this possible in current .net framework like 3.5 SP1 or 4.0 using c#?

Thanks.


To make an additional entry in windows explorer context menu You would need to add two sub keys in windows registry at HKEY_CLASSES_ROOT\Folder\shell

These keys are:

  1. Folder\shell\MyProduct : Value of this key will be shown as text in the new windows explorer context menu item. You can also add a icon to the context menu item by adding a value to the key 1 and name it "Icon" then set path to icon as value.

  2. Folder\shell\MyProduct\command: Set the path of application which you want to launch.

Here is the link for more details and sample C# code: http://newapputil.blogspot.in/2016/12/adding-new-item-to-context-menu-of.html


Adding an Application to the Right Click on Every Folder

Here is how to add any application to the Context Menu when you right click on any Folder. This way you do not have to always go to the Start Menu. When you right click on any folder, you can have access to that application, the same as using Sent To.

  1. Open RegEdit
  2. Go to HKEY_CLASSES_ROOT\Folder\shell
  3. Add a new Key to the "Shell" Key and name it anything you like.
  4. Give it a default value that will appear when you right click a folder, i.e. NewKey (use an "&" without the quotes, in front of any character and it will allow you to use the keyboard)

  5. Click on the Key HKEY_CLASSES_ROOT\Folder\shell\NewKey

  6. Add a New Key named Command
  7. Set the (Default) value of the application you want to run
  8. For example: c:\program files\internet explorer\iexplore.exe (Include the full path and parameters if you need them)

Writing code for you....

Edit:

code in C# (for folders)

 private void button1_Click(object sender, EventArgs e)
    {           
        Microsoft.Win32.RegistryKey contextMenuKey = Registry.ClassesRoot.CreateSubKey(@"Folder\shell\MyName\command"); 
        //MyName is name to display
        contextMenuKey.SetValue(null, @"c:\program files\internet explorer\iexplore.exe");  
        //null or "" to set value in (Default), full path of your application
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜