I was wondering how to add a new function or button to a right-click event in Windows. For example, lets say I wanted to add a "Add to Zip" function that something like WinRar or WinZip provides. After installation anytime you right click on a file the option "Add to Zip" is available. How can I get my own button with my own code ( not really adding to zip) to display after a right click? Can I specify to only display on certain file formats?
Explorer uses the registry and shell extensions to generate the menu. Each file type (.ZIP, .RAR, etc) can have separate entries. Each file extension is mapped to a file type in HKCR. The file type then contains a subkey called Shell. Under here is a subkey for each menu option and the command to execute when it is clicked. For example most file types will have an Open subkey and the default value will be the program to execute. For simple commands this works well.
For more complex interactions you need to create a COM-based shell extension. This is beyond the scope of this topic but you can find info in MSDN. Note that it is generally recommended that you do not use managed code for it because it must interact with the shell but it can work and, in fact, MS provided an example where the command prompt ran through the shell. You can search online for it.
Michael Taylor - 3/5/07
Thanks for the help everyone!
I have looked at the articles provided however I am having a problem. I need to parse the path of the file that is being right clicked. You see I have a few drives mapped, so for example when I open someFolder\sample.html on my H drive it will open in it in Internet explorer with the path "H:\someFolder\sample.html". However I want to create a context menu link that will be able to open the file with a given server name, so for example if I was to do the same as the example just given it would instead open it in Internet Explorer with the path http://serverName/someFolder/sample.html
Is this possible? I have tryed looking up Shell and Batch commands but none of them let me manipulate strings. I believe the filename is stored under the %1 or the %L.
See http://blogs.msdn.com/oldnewthing/archive/2006/12/18/1317290.aspx on why you should not write in-process shell extensions (like an Explorer right-click/context menu) in .NET...
Correct me if I'm wrong, but for my purpose I do not think I will need to write a shell extension. Isn't there any simplier way to do this? I just need to take a string, chop off the first 3 characters and then add in my own string at the beggining. However I need to program this to be run in a bat file, any ideas anyone?
If you want to do something with a menu or menu item when the user right-clicks a file in Windows Explorer, that is done through a in-process Shell extension.
Tareq Ismail wrote: Correct me if I'm wrong, but for my purpose I do not think I will need to write a shell extension. Isn't there any simplier way to do this? I just need to take a string, chop off the first 3 characters and then add in my own string at the beggining. However I need to program this to be run in a bat file, any ideas anyone?