Create context-menu entries for a given extension
Asked Answered
F

1

0

It is possibe to create context menu entries for Window's File Explorer for all files by creating registry entries such as

[HKEY_CLASSES_ROOT\*\shell\kdb-test]
@="Test (*,kdb-test)"
[HKEY_CLASSES_ROOT\*\shell\kdb-test\command]
@="cmd.exe /c type %1 & pause"

It is also possible to create them for a given extension by replacing \* \ by \.extension\.

However, I have found that the latter doesn't work reliably. For instance,

[HKEY_CLASSES_ROOT\.regshelltest\shell\kdb-test]
@="Test (.regshelltest,kdb-test)"
[HKEY_CLASSES_ROOT\.regshelltest\shell\kdb-test\command]
@="cmd.exe /c type %1 & pause"

will override the difinition for *, as intended, but doing the same for .pdf or .txt won't work on my system.

The documentation suggestest as clean solution to use an indirect structure instead,

[HKEY_CLASSES_ROOT\.txt]
@="PlainTextFile"
[HKEY_CLASSES_ROOT\PlainTextFile\shell\kdb-test]
@="Test (PlainTextFile,kdb-test)"
[HKEY_CLASSES_ROOT\PlainTextFile\shell\kdb-test\command]
@="cmd.exe /c type %1 & pause"

but that doesn't work either. Additionally, it reduces compatibility, as it strongly assumes that everyone defining such registry entries uses the same file type name for the extension (couter-example: .pdf being set to PDFXChangeEdit.PDF), so defining the actions based on the extension would be preferable – especially for user-created shell extensions.

A similar issue was discussed in “Registry keys for context menu entries written, but no context menu entries”, but there the suggested solution is to query the "ProgID" (i.e. the file name type as specified by the HKEY_CLASSES_ROOT\.extension key), which didn't work for me.

Is there some reliable way to create these context-menu entries based on file-extensions, that doesn't depend on the ProgID set?

As a workaround, in “Add a Windows Shell context menu entry for a specific extension (not file type)” it has been suggested to use the \*\ key with the AppliesTo filter. It does however feel like a workaround rather than a clean solution, so I am looking for a possibility to cleanly and reliably use the HKEY_CLASSES_ROOT\.extension\shell interface.

Fowler answered 22/5, 2019 at 11:43 Comment(0)
R
1

Windows XP added a method to add supplementary verbs to a file extension without relying on the prog-id; the HKEY_CLASSES_ROOT\SystemFileAssociations key. You can register for a specific extension or a perceived file type (text, video etc.).

Putting your registration directly in the .extension key is unreliable, it does not work correctly when the extension has a functioning prog-id.

Putting the registration in the prog-id is the correct way to do it when you want to change the default action and it has worked this way since at least Windows 95. What has changed over time however is how the prog-id is determined. At some point a undocumented Explorer related key started controlling what the .extension to prog-id mapping is and to prevent applications from changing the users defaults, this information is now "encrypted".

The current guidance is that for a extension where you want to be the default verb you register the prog-id in the normal fashion and point the extension to this prog-id. If this extension has already been claimed by another prog-id then the user has to manually change the default, you cannot to it programmatically. You probably want to register yourself with Default Programs so your application appears in the Default Programs UI in control panel.

Ragged answered 22/5, 2019 at 12:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.