Create custom right-click context menu item with C# for all desktop shortcuts (windows explorer)

不羁岁月 提交于 2020-01-02 08:39:09

问题


The problem is easy: I've a lot of desktop shortcuts which points to a lot of file, BUT I also have a lot of shortcuts which points to directories pointed by those shortcuts. I want to remove this redundance by simply adding another rightclick menu options for all shortcuts (.lnk files) that allows you to open explorer.exe to the directory containing the file pointed.

While I discovered how to retrive the target of a shortcut and it's working, I found a suggestion on how adding a menu item to rightclick context menu, but it's not working (I put a key under HKCR*\shellext\ContextMenuHandlers called Test and set the base value to "cmd.exe"

But it doesn't work, obviusly

any suggestion?

Update 1: How to add an icon to that menu item?What size should the icon file have? 16x16 or 32x32?

thanks in advance


回答1:


Go into HKCR\lnkfile

Create a new key called "shell", and below that create another key called whatever you want the display text to be for your context menu handler, I called mine "COMMAND".

Next, create yet another key below that called specifically "command" and make the (Default) value be "cmd.exe", which will be the path to your custom command. Remember to wrap it in quotes if you're going to be pointing to an exe that has spaces.

So for this example, the final key ends up being:

HKCR\lnkfile\shell\COMMAND\command\

Add the (Default) value mentioned above and your test will be working fine.

Additionally, you can use "%1" to specify the full path to the .lnk file being accessed by the context menu, again remember to wrap it in quotes since you never know if it'll be a file that has spaces in it's full path.



来源:https://stackoverflow.com/questions/3664046/create-custom-right-click-context-menu-item-with-c-sharp-for-all-desktop-shortcu

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!