为给定扩展名创建上下文菜单条目 [英] Create context-menu entries for a given extension

查看:75
本文介绍了为给定扩展名创建上下文菜单条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以通过创建注册表项(例如

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"

也可以通过将 \ * \ 替换为 \.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"

将覆盖 * 的定义,因为打算,但是对 .pdf .txt 进行的操作在我的系统上将无效。

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"

但这也不起作用。此外,它会降低兼容​​性,因为它强烈假定定义此类注册表项的每个人都使用相同的文件类型名称作为扩展名(计算机示例:.pdf设置为 PDFXChangeEdit.PDF ),因此最好基于扩展名定义操作-特别是对于用户创建的shell扩展。

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.

已编写上下文菜单项的注册表项,但没有上下文菜单项,但是建议的解决方案是查询 ProgID(即文件名) HKEY_CLASSES_ROOT\.extension 键指定的类型),对我不起作用。

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.

是是否有一些可靠的方法可以基于文件扩展名创建这些上下文菜单项,而这不依赖于 ProgID 集?

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

作为解决方法,请在 为特定扩展名(不是文件类型)添加Windows Shell上下文菜单项,建议使用 \ \ * \ 键和 AppliesTo 过滤器。但是,它的确感觉是一种解决方法,而不是一种干净的解决方案,因此,我正在寻找一种清洁,可靠地使用 HKEY_CLASSES_ROOT\.extension\shell 界面的可能性。 / p>

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.

推荐答案

Windows XP添加了一种在不依赖于prog-id的情况下向文件扩展名添加补充动词的方法; HKEY_CLASSES_ROOT\SystemFileAssociations 。您可以注册特定的扩展名或可感知的文件类型(文本,视频等)。

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.).

直接将注册内容放入 .extension 密钥不可靠,当扩展名具有有效的prog-id时,它无法正常工作。

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

将注册内容放入prog-id要更改默认操作时的正确方法,并且至少从Windows 95开始,这种方法就一直有效。但是,随着时间的推移,如何确定prog-id的方法已经有所改变。在某个时候,一个未记录的与Explorer相关的密钥开始控制.prong-id映射到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".

当前的指导原则是,对于要用作默认动词的扩展名,请以常规方式注册prog-id,并将扩展名指向该prog-id。如果此扩展名已被另一个prog-id声明,则用户必须手动更改默认值,因此无法以编程方式对其进行更改。您可能想使用默认程序注册自己,所以您的应用程序将显示在控制面板的默认程序用户界面中。

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.

这篇关于为给定扩展名创建上下文菜单条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆