如何在 Windows shell 中向文件类型添加辅助动词? [英] How does one add a secondary verb to a file type in Windows shell?

查看:41
本文介绍了如何在 Windows shell 中向文件类型添加辅助动词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Windows shell 编程的基本思想是,您可以将给定的文件类型(扩展名)与 MS 当前调用的 progid(例如 Company.Type.Ver)相关联:

The basic idea with Windows shell programming is that you can associate a given file type (extension) with what MS is currently calling a progid (e.g. Company.Type.Ver):

HKCR\.txt@=Acme.Text.1

HKCR\.txt @=Acme.Text.1

HKCR\Acme.Text.1@=这是 Acme 文本文件关联的 progid

HKCR\Acme.Text.1 @=This is the progid for text file associations for Acme

然后 Acme Corp 可以放任意数量的 shell 动词作为 HKCR\Acme.Text.1\shell 的子键,例如 HKCR\Acme.Text.1\shell\open.

And then Acme Corp can put as many shell verbs as they want as subkeys of HKCR\Acme.Text.1\shell such as HKCR\Acme.Text.1\shell\open.

但如果我是 XyzCorp,我该如何在文本文件中添加次要动词?

But if I'm XyzCorp, how do I add a secondary verb to text files?

我不想篡改主文件关联 - 我很高兴将它关联到 Acme.Text.1,但我想添加导入到 Xyz 编辑器".

I don't want to usurp the primary file association - I'm happy for it to be associated to Acme.Text.1, but I want to add "Import into Xyz Editor".

我可以:
1. 给 Acme 的 progid 添加一个动词(例如 HKCR\Acme.Text.1\shell\my-verb)
2. 代表我们创建一个新的 progid 并将 Acme 的数据复制到该 progid 中,并将 XyzCorp 的动词合并到其中
3. 直接在文件扩展名中添加动词(至少曾经可以这样做)
4.???

I could:
1. add a verb to Acme's progid (e.g. HKCR\Acme.Text.1\shell\my-verb)
2. create a new progid on both our behalfs and copy Acme's data to that, and merge XyzCorp's verbs into that
3. add verbs directly to the file extension (at least one used to be able to do so)
4. ???

有人知道这个问题的正确"答案吗?

Does anyone know the "right" answer to this?

对于任何涉及必须修改其他人的 PROGID 的解决方案,我真的不感到兴奋.我真的希望添加一些东西 - IContextMenu 或任何需要的东西,在关联的 PROGID 之外添加额外的动词/选项到给定的文件类型.

I'm really not thrilled with any solution that involves having to modify someone else's PROGID. I really would prefer to add something - an IContextMenu or whatever is required, outside of the associated PROGID to add additional verbs / options to a given file type.

ext->progid 似乎是一个疯狂的系统,其中 progid 由各个开发公司拥有,并且可以随意删除或更改.这让我觉得很脆弱(卸载某些东西然后噗噗,你的文件扩展名停止正常工作,或者安装某些东西,同样你的次要动词消失了,因为 ext 现在映射到一个不同的专有 PROGID,我没有在其中添加我们的动词.已安装(当时还不知道关于这个其他尚不存在的 progid 的任何信息)),并且只是愚蠢的.这么长时间以来,所有这些版本的 Windows 和 Microsoft 从未想出一种方法来为给定的文件类型设置处理程序层?真的吗?!?

It seems like such a crazy system to have ext->progid where progid is owned by individual development houses, and can be deleted or changed by such at will. This strikes me as fragile (uninstall something and poof, your file extension stops working properly, or install something and likewise your secondary verb disappears because ext is now mapped to a different proprietary PROGID to which I didn't add our verb to when we were installed (not, at that time, knowing anything about this other as-yet-nonexistent progid)), and just dumb. After all this time, all these versions of Windows, and Microsoft has never figured out a way to have layers of handlers for a given file-type? Really?!?

我只是觉得这令人震惊!初级编程 101 涉及学习命令模式或其他分层/级联系统.Windows WinProcs 本身以命令模式模式组织 - 因此从内部窗口上下文到外部,许多可能的处理程序在给定的 MSG 处被给予一个裂缝.

I just find that flabbergasting! Junior programming 101 involves learning command-pattern or other layered / cascading systems. Windows WinProcs themselves are organized in a command-pattern pattern - so that from the inner window context to the outer, many possible handlers are given a crack at a given MSG.

当然有一种方法可以在不覆盖扩展的主要 progid 关联的情况下添加适用于多个扩展的动词,它本身完全独立于主要扩展->progid 映射(以便用户可以随着时间的推移安装多个程序,并且仍然可以访问该文件类型的辅助动词).

Surely there is a way to add a verb that applies to several extensions without overriding the extensions' primary progid association, which is itself totally independent of the primary extension->progid mapping (so that the user can install multiple programs over time, and still have access to a secondary verb for that file type).

我想我可以看看 HKCR.* ...我知道可以在那里添加适用于所有文件类型的动词.但是,我需要找到某种过滤方式,以便我们的动词只真正出现在我们应该应用到的那些实际文件类型中...

I suppose I can look at HKCR.* ... I understand its possible to add verbs there which apply to all file types. But then, I need to find some way to filter so that our verb is only really present for those actual file types we should apply to...

推荐答案

这是可能的,而且很容易做到(一旦你知道去哪里找).神奇之处在于 HKEY_CLASSES_ROOT\SystemFileAssociations 键.在这里您会发现许多以文件扩展名命名的子项.只需在这些下创建所需的 shell/open/command 键.

This is possible, and it's very easy to do (once you know where to look). The magic lies in the key HKEY_CLASSES_ROOT\SystemFileAssociations. Here you will find many subkeys named after file extensions. Simply create your desired shell/open/command keys under these.

这是一个显示结构的示例注册表文件.如果您将其另存为 .reg 文件并导入它,那么您将在所有 .txt 文件中添加导入到 Xyz 编辑器"命令,并且不会影响主文件关联:

Here is an example registry file showing the structure. If you save this as a .reg file and import it, then you'll get the "Import into Xyz Editor" command added to all .txt files, and without affecting the primary file association:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\SystemFileAssociations\.txt]

[HKEY_CLASSES_ROOT\SystemFileAssociations\.txt\shell]

[HKEY_CLASSES_ROOT\SystemFileAssociations\.txt\shell\xyz-import]
@="Import into Xyz Editor"

[HKEY_CLASSES_ROOT\SystemFileAssociations\.txt\shell\xyz-import\command]
@="notepad.exe \"%1\""

HKCR\SystemFileAssociatons 下还有一些没有以扩展名命名的键:text"、image"、video"等.它们对应于 PerceivedTypeHKCR 扩展项下的条目.例如,HKCR\.png\PerceivedType 设置为image",HKCR\.jpg\PerceivedType 也是如此,因此您可以在 HKCR 下添加处理程序\SystemFileAssociations\image 将出现在所有图像"类型中.

Also under HKCR\SystemFileAssociatons are a few keys not named after extensions: "text", "image", "video", etc. These correspond to the PerceivedType entries under extensions in HKCR. For example, HKCR\.png\PerceivedType is set to "image", and so is HKCR\.jpg\PerceivedType, so you could add handlers under HKCR\SystemFileAssociations\image which will appear for all "image" types.

这篇关于如何在 Windows shell 中向文件类型添加辅助动词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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