将文件扩展名与程序相关联 [英] Associating file extensions with a program

查看:74
本文介绍了将文件扩展名与程序相关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道怎么做,我去过 http://www.codeproject.com/KB/vb/VBFileAssociation.aspx 之前.我的问题是这样做有什么作用,是否有可能逆转它?如果您不知道您的程序将在哪里,而您现在只是在测试它,该怎么办?有什么方法可以找到"您的程序,或者有什么简单的方法可以编辑它的打开位置?就此而言,是否可以判断文件是否已经关联,尝试重新关联是否有问题?最后,如何设置它使用的 .ico 文件?

I get how to do it, and i have been to http://www.codeproject.com/KB/vb/VBFileAssociation.aspx before. My question is about what doing that does, is it possible to reverse it? What if you do not know where your program will be, and you are just testing it for now? Is there any way for it to "find" your program, or an easy way to edit where it is opened? For that matter, is it possible to tell if the file has been associated already, is it an issue to try and reassociate? Finally, how can you set the .ico file it uses?

感谢您的帮助,我对注册表几乎一无所知,这让我很困惑,哈哈...

Thanks for the help, I know almost nothing about the registry and it confuses me lol...

推荐答案

为简洁起见,我使用了一个假的根键.在实践中,将 Hive_Key 替换为系统默认设置的 HKEY_LOCAL_MACHINE 或每个用户设置的 HKEY_CURRENT_USER .允许存在这些键中的任何一个,或两者都存在.如果它们都存在,则 HKCU 键优先.

For brevity, I'm using a fake root key. In practice, replace Hive_Key with HKEY_LOCAL_MACHINE for system default settings, or HKEY_CURRENT_USER for per-user settings. Either of these keys are allowed to exist, or both. If they both exist, the HKCU key takes precedence.

要将扩展名与文件类型相关联,您需要将扩展​​名键 (Hive_Key\Software\Classes\.ext) 的默认值设置为所选文件类型,通过设置默认值关键值.

To associate an extension with a file type, you need to set the default value of the extension key (Hive_Key\Software\Classes\.ext) with a chosen file type, by setting the default key value.

实际启动的程序以及其他文件类型的详细信息可以在文件类型中找到.文件类型由所谓的 ProgID(Programmatic Identifier"的缩写,它是类标识符的更易于阅读的版本)表示.ProgID 键位于 Hive_Key\Software\Classes 中,此插图的示例值可能是 ext_auto_key.

The actual program launched, as well as other file type details, are found in the file type. File types are noted by what is referred to as a ProgID (short for "Programmatic Identifier", which is a more easily readable version of a Class Identifier). ProgID keys are found in Hive_Key\Software\Classes, and an example value for this illustration might be ext_auto_key.

ProgID 可能有一个默认值,它将是资源管理器中文件类型的友好描述(例如,Microsoft Word 文档").您需要确保选择用户易于理解的描述.

The ProgID may have a default value, which will be the friendly description of the file type in Explorer (such as, "Microsoft Word Document"). It's up to you to make sure you choose a description that's easily understandable for users.

ProgID 可能有一个子键,DefaultIcon,它是存储文件类型图标的地方.该图标路径是该键的默认值.

The ProgID may have a subkey, DefaultIcon, which is where the file type icon is stored. That icon path is the default value of that key.

ProgID 键可能是一个子键,shell,它将包含文件上的上下文菜单项,以及该上下文菜单项将调用的程序.与 ProgID 的默认值类似,动词键的默认值是将显示在上下文菜单上的文本.此 shell 键的默认值具有默认动词键名称,即用户双击文件时调用的动词.

The ProgID key may a subkey, shell, which will contain the context menu items on the files, and the program that that context menu item will invoke. Similar to the default value of the ProgID, the default value of the verb key is the text which will show up on the context menu. The default value of this shell key has the default verb key name, which is the verb invoked when the user double clicks a file.

这些上下文菜单项是动词.对于我们的示例,使用记事本打开文件的动词如下所示:Hive_Key\Software\Classes\ext_auto_file\shell\open\command 使用默认值 notepad.exe %1.

These context menu items are Verbs. For our example, a verb that opens the file with Notepad would look like this: Hive_Key\Software\Classes\ext_auto_file\shell\open\command with default value notepad.exe %1.

这是您放置程序路径的地方.如果您的程序在系统 PATH 中,就像 notepad.exe 一样,您不需要需要指定完整路径.在更有可能的情况下,您需要指定 exe 的路径.出于测试目的,您可以将其设置为您的构建目录.

This is where you would put your program path. If your program is in the system PATH, as notepad.exe is, you don't need to specify the full path. In the more likely case, you'd need to specify the path to your exe. For testing purposes, you can just set it to be your build directory.

您询问了如何检查这些东西,这可以通过首先检查扩展键的默认值以获取 ProgID,然后检查 ProgID 键的 shell 子键以获取默认值来完成动词,然后检查 \shell\verb\command 以获取启动程序的路径.

You asked how to check this stuff, and this can be done by first inspecting the default value of the extension key to get the ProgID, then inspecting the shell subkey of the ProgID key to get default verb, then inspecting \shell\verb\command to get the path to the program launched.

打开 regedit.exe 并浏览其他文件类型的注册表项以更好地了解其工作原理可能会有所启发.

It might be enlightening to open regedit.exe and browse those registry keys for other file types to get a better idea of how it all works.

此外,如果特定扩展不受控制面板中设置为默认(默认程序)的程序的控制,则上述所有内容均有效.您可以通过检查密钥 HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ Explorer\FileExts\.EXT\UserChoice 是否存在来检查此状态.如果是,您将需要在您的自定义生效之前撤销默认程序控制.这可以通过删除 UserChoice 子项来完成.

Also, the above is all valid if the particular extension is not under control of a program set as default (Default Programs) in the Control Panel. You can check this status by checking of the existence of the key HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ Explorer\FileExts\.EXT\UserChoice. If it is, you will need to revoke Default Programs control before your customizations will go into effect. This can be done by deleting that UserChoice subkey.

这篇关于将文件扩展名与程序相关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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