Windows 7 文件扩展名关联 [英] Windows 7 file extension association

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

问题描述

我特指 Windows 7.

I am referring specifically to windows 7.

我有代码将某个扩展与我的应用程序相关联,正如 webJose 在以下页面上提出的那样:哪些注册表项负责文件扩展关联?(但是我正确写入 HKEY_CURRENT_USER\Software\Classes 而不是 HKEY_CLASSES_ROOT 建议)

I have code that associates a certain extension with my application as proposed by webJose on the following page: What registry keys are responsible for file extension association? (However i correctly write to HKEY_CURRENT_USER\Software\Classes instead of HKEY_CLASSES_ROOT as suggested)

以上最初有效,或者如果没有与扩展相关的其他程序.但是,在使用 Windows 7 内置选择默认程序..."(在打开方式"下的文件右键单击上下文菜单下)后,它会将扩展名与您选择的任何新程序重新关联.

The above works initially, or if there are no other programs associated with the extension. However after using the Windows 7 built-in "Choose default program..." (found under the file-right-click context menu under "Open with") it re-associates the extension with whatever new program you choose.

此时发生的情况是HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\\UserChoice"被系统更改,因此新选择的程序接管.

What happens at this point is that "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\\UserChoice" is changed by the system, and so the newly selected program takes over.

运行上面的代码,重新获得对扩展的控制是行不通的.重新获得控制权的唯一方法是:

Running the above code, to regain control over the extension will not work. The only way to regain control, is by either:

  1. 编辑 UserChoice -> Progid 值,这是不允许的(无论是通过编程还是使用 regedit.exe - 访问被拒绝).
  2. 或者删除 UserChoice 值并确保您的应用程序是 \OpenWithList 下 MRUList 值中的第一个(这可以使用 regedit.exe 实现,但不能以编程方式实现)

我的问题是:有没有办法以编程方式实现这一目标?扩展程序与其他程序关联后,可以更改哪些注册表值以重新获得对扩展程序的控制权?

My question is: Is there a way to achieve this programmatically? What registry values can be changed to regain control of an extension, after is associated with another program?

我知道,如果用户通过资源管理器将关联的应用程序设置为扩展程序,这似乎很明显,它会再次以相同的方式将扩展程序重新关联到不同的应用程序.

I know it might seem obvious that if a user through explorer sets the associated application to an extension, that it would be expected to do it the same way again to re-associate the extension to a different application.

然而,问题是我的应用程序中有一个按钮,它使用上述代码来检查扩展程序与我的应用程序的关联.不幸的是,在上述情况下,我的应用程序显示一条消息,确认扩展程序已成功关联,但未成功关联!那么有没有办法解决这个问题?

The problem however is I have a button in my application that uses the above mentioned code to check for extension association with my application. Unfortunately with the above situation, my application displays a message confirming that the extension is already successfully associated when its not! So is there a way around this?

推荐答案

删除 UserChoice 应将默认程序恢复为标准文件关联键(以 HKCU 中的 ProgID 开头).除非您还可以删除 OpenWithList,否则会以极端的偏见恢复.

Deleting UserChoice should revert the default program to the standard file association keys (which starts with the ProgID in HKCU). Barring that you could also delete OpenWithList, which would be reverting with extreme prejudice.

查看注册表项安全和访问权限MSDN,特别是 RegSetKeySecurity 函数.请记住,您需要先授予自己对该密钥的管理控制权,然后才能删除它.

Check out Registry Key Security and Access Rights on MSDN, particularly the RegSetKeySecurity function. Remember that you'll need to grant yourself administrative control to the key before you can delete it.

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

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