将文件扩展名与程序关联

发布于 2024-08-07 17:55:33 字数 360 浏览 2 评论 0原文

我知道如何做到这一点,并且我去过 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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一个人练习一个人 2024-08-14 17:55:33

为简洁起见,我使用假根密钥。实际上,对于系统默认设置,请将 Hive_Key 替换为 HKEY_LOCAL_MACHINE,或者对于每用户设置替换 HKEY_CURRENT_USER。这些键中的任何一个都可以存在,或者两者都存在。如果它们都存在,则 HKCU 键优先。

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

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

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

ProgID 可能有一个子项DefaultIcon,它是存储文件类型图标的位置。该图标路径是该键的默认值。

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

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

这是您放置程序路径的位置。如果您的程序位于系统路径中(如 notepad.exe),则您不需要指定完整路径。在更可能的情况下,您需要指定 exe 的路径。出于测试目的,您只需将其设置为构建目录即可。

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

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

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

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文