How does one add a secondary verb to a file type in Windows shell?

不羁岁月 提交于 2019-12-03 07:26:06

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.

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\""

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.

The unnamed value (aka default or standard value) under the file extension key can be a progID, but doesn't have to be. It's really just an identifier. It's ok for you to add your verbs under the file type identifier even if it looks like someone else's name is there. The next paragraphs consider each of the options.

1. add a verb to Acme's progid (e.g. HKCR\Acme.Text.1\shell\my-verb)

This one gets my vote. It's simple and effective. Upgrades/reinstallation of ACME's software will not affect verbs that you have added to ACME's file type/progid. Uninstalling Acme's software will typically not remove your verbs, since uninstallers usually do not remove registry keys contaning subkeys that they did not create.

2. create a new progid on both our behalfs and copy Acme's data to that, and merge XyzCorp's verbs into that

This would work at the time the change but will stop to work when Acme's program is upgraded/reinstalled - the installer will not know to update the shared file type. Similarly, when Acme's uninstaller is run, it will not remove the verbs, so they will be dangling commands to a non-existent path.

3. add verbs directly to the file extension (at least one used to be able to do so)

I just tried this on Win XP SP3, and unfortunately it didn't work. The verbs have to be set under the file type key, not the file extesion key.

4. ???

You could create a ContextMenu Handler - this is a shell extension and requires implementing COM interfaces. An overview of the differences and benefits of context menu handlers compared to simple registry-configured verbs is described in Shell Context Menu.

Summary For simplicity, I'd go with #1. XYZCorp's installer can check if a file type exists for the file extension, and if so adds verbs under the existing type, or it creates a new file type if one does not exist and registers the verbs under that.

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