1

I just learned how to create a context menu for the Desktop, but what I really want is to only have the context menu for one specific link. Is this possible? I have not figured out how yet. I was hoping to specify the file instead of an extension in HKEY_CLASSES_ROOT, but I have not gotten been able to get it to work. This is my most current attempt.

[HKEY_CLASSES_ROOT\Applications\My Link.lnk\Shell\Toggle]
"Position"="Top"
"Icon"="\"C:\\Program Files (x86)\\My Toggle\\My Toggle.Exe\""
@="Toggle"

[HKEY_LOCAL_MACHINE\Software\Classes\My Link.lnk\shell\Toggle\command]
@="\"C:\\Program Files (x86)\\My Toggle\\My Toggle.Exe\""
David King
  • 91
  • 9
  • I would like it to work like. `[HKEY_CLASSES_ROOT\DesktopBackground\Shell\PowerSribe Switch] "Position"="Top" "Icon"="\"C:\\Program Files (x86)\\My Toggle\\My Toggle.Exe\"" @="Toggle" [HKEY_CLASSES_ROOT\DesktopBackground\Shell\PowerSribe Switch\command] @="\"C:\\Program Files (x86)\\My Toggle\\My Toggle.Exe\""` – David King May 03 '17 at 21:13

2 Answers2

1

In case someone else is trying to do the same type of thing. My best solution was to create a new shortcut type extension called .lnky, and assign the context menu to it. Unless I am missing something I was not able to find a way to create a context menu for a single file and not a file extension.

This guide helped a lot: Add menu item to windows context menu only for specific filetype

[HKEY_CLASSES_ROOT\.lnky]
@="lnkyfile"

[HKEY_CLASSES_ROOT\lnkyfile]
@="Shortcut"
"IsShortcut"=""
"NeverShowExt"=""
[HKEY_CLASSES_ROOT\lnkyfile\Shell\My Toggle]
"Position"="Top"
"Icon"="\"C:\\Program Files (x86)\\My program\\My program.Exe\""
@="My Action"
[HKEY_CLASSES_ROOT\lnkyfile\Shell\My Toggle\command]
@="\"C:\\Program Files (x86)\\My program\\My program.Exe\""

The result of this is when I right clink on my lnky file it has my action next to my program icon at the top of the context menu. My program.Exe runs when I click on My Action.

Community
  • 1
  • 1
David King
  • 91
  • 9
  • After testing this on a second PC, I realized that in order to make the file still act like a link file, I had to do one more step. Export HCR\lnkfile. Open it in a text editor [replace all] "lnkfile" with "lnkyfile" and then Merge the reg file back into the registry. The final result looked like. – David King May 05 '17 at 14:44
  • `[HKEY_CLASSES_ROOT\lnkyfile] @="Shortcut" "IsShortcut"="" "NeverShowExt"="" "EditFlags"=dword:00000001 "FriendlyTypeName"="@shell32.dll,-4153" [HKEY_CLASSES_ROOT\lnkyfile\CLSID] @="{00021401-0000-0000-C000-000000000046}" [HKEY_CLASSES_ROOT\lnkyfile\Shell] [HKEY_CLASSES_ROOT\lnkyfile\Shell\PowerSribe Toggle] "Position"="Top" "Icon"="\"C:\\Program Files (x86)\\My Program\\My Program.Exe\"" @="My Action" [HKEY_CLASSES_ROOT\lnkyfile\Shell\PowerSribe Toggle\command] @="\"C:\\Program Files (x86)\\My Program\\My Program.Exe\"" [HKEY_CLASSES_ROOT\lnkyfile\shellex]` – David King May 05 '17 at 14:45
  • ``[HKEY_CLASSES_ROOT\lnkyfile\shellex\ContextMenuHandlers] [HKEY_CLASSES_ROOT\lnkyfile\shellex\ContextMenuHandlers\Compatibility] @="{1d27f844-3a1f-4410-85ac-14651078412d}" [HKEY_CLASSES_ROOT\lnkyfile\shellex\ContextMenuHandlers\NvAppShExt] @="{A929C4CE-FD36-4270-B4F5-34ECAC5BD63C}" [HKEY_CLASSES_ROOT\lnkyfile\shellex\ContextMenuHandlers\OpenContainingFolderMenu] @="{37ea3a21-7493-4208-a011-7f9ea79ce9f5}"` – David King May 05 '17 at 14:47
  • `[HKEY_CLASSES_ROOT\lnkyfile\shellex\ContextMenuHandlers\OpenGLShExt] @="{E97DEC16-A50D-49bb-AE24-CF682282E08D}" [HKEY_CLASSES_ROOT\lnkyfile\shellex\ContextMenuHandlers\{00021401-0000-0000-C000-000000000046}] @="" [HKEY_CLASSES_ROOT\lnkyfile\shellex\DropHandler] @="{00021401-0000-0000-C000-000000000046}" [HKEY_CLASSES_ROOT\lnkyfile\shellex\IconHandler] @="{00021401-0000-0000-C000-000000000046}" [HKEY_CLASSES_ROOT\lnkyfile\shellex\PropertySheetHandlers] [HKEY_CLASSES_ROOT\lnkyfile\shellex\PropertySheetHandlers\ShimLayer Property Page] @="{513D916F-2A8E-4F51-AEAB-0CBC76FB1AF8}"` – David King May 05 '17 at 14:48
  • Thanks for your answer. I couldn't find another solution neither. But, could you please tell me how you created an shortcut file with that exension that actually executes its target .exe? I did all your steps.. and windows recognizes the extension as shortcut when i rename a *.lnk file to *.lnky via notepad, but it doesn't execute the target. (I don't mean the context menu, that works fine;) ) – Blood_Working Jan 06 '20 at 00:35
  • ***Export HCR\lnkfile. Open it in a text editor [replace all] "lnkfile" with "lnkyfile" and then Merge the reg file back into the registry. *** **This step is what should make .lnky work the same as .link** *Make certain you replaced all instances of .link with .lnky* – David King Jan 07 '20 at 17:24
  • Ok, but I meant how to exactly create the shortcut file (manually). Just creating a normal .lnk file via 'Create Shortcut' and then rename it to .lnky via notepad? – Blood_Working Jan 07 '20 at 23:17
  • Yes, create normal shortcut then rename from .lnk to .lnky – David King Jan 09 '20 at 12:15
1

The old fashioned way of creating interfaces to COM objects (Namely IContextMenu) You can then check all files passed to the handler in its Initialize method, using DragQueryFile to access information about the files passed, or in the QueryContextMenu, where actual menu items are added.
There, you could simply not add menu items unless it is the specific file you want it for. Other menu handlers for the file type would still add their own menu items.

Note the shortcut link will be resolved, so your handler would be looking at the file linked to rather than the shortcut itself. How to retrieve info about the actual lnk file is how I stumbled across this and I still don't know!