从注册表中读取已知的文件扩展名/类型 [英] read known file extensions / types from the registry

查看:59
本文介绍了从注册表中读取已知的文件扩展名/类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向用户显示已知文件扩展名的列表,供他选择.我知道这些通常以如下方式存储在HKEY_CLASSES_ROOT下的注册表中:

I want to present the user with a list of known file extensions for him to pick. I know that these are stored in the Registry under HKEY_CLASSES_ROOT usually like this:

.txt->(默认)="txtfile"

.txt -> (default)="txtfile"

然后txtfile包含有关关联程序等的信息.

where txtfile then contains the information about associated programs etc.

不幸的是,注册表中的该位置还存储了许多其他键,例如文件类型(例如txtfile)和条目,例如

Unfortunately that place in the registry also stores lots of other keys, like the file types (e.g. txtfile) and entries like

CAPICOM.Certificates(无论是什么)

CAPICOM.Certificates (whatever that is)

如何确定哪些条目是文件扩展名?还是有其他方法来获取这些扩展(例如API函数)?

How do I determine which of the entries are file extensions? Or is there a different way to get these extensions like an API function?

(我不认为这很重要,但是我在程序中使用的是Delphi.)

(I don't think it matters, but I am using Delphi for the program.)

推荐答案

不能保证HKEY_CLASSES_ROOT中每个键后面都有点的键都用于文件关联,但是每个文件关联都需要先创建一个点之前的键.请参见文件类型主题上的MSDN.

There is no guarantee that every keys preceded by a dot in HKEY_CLASSES_ROOT is intended for file association, but every file association requires creation of a key preceded by a dot. See MSDN on File Types topic.

AFAIK,我在这里描述的方法与Windows 设置文件关联功能如何工作以获取所有已知文件类型的列表一致.这是基于我以前研究该主题时的观察结果.

AFAIK, the method I describe here conforms with how the Windows Set File Associations feature works to get a list of all known file types. It was based on my former observation when I delved into this subject.

要实现这一目标,您需要执行以下复杂步骤:

To achieve that, you'll need to do intricate steps as follows:

  1. 枚举点号之前的每个键.,您可以为此使用RegQueryInfoKey()和RegEnumKeyEx().

  1. Enumerating every keys preceded by a dot . , you can use RegQueryInfoKey() and RegEnumKeyEx() for this purpose.

在每个带点号的键中,查看默认值数据:

In every keys preceded by a dot, look at the default value data:

a..如果默认值为不为空,则这足以表明先前的点键"旨在用于所有Windows NT中的文件关联版本,然后尝试打开值数据中提到的键名,只说 TheKeyNameMentioned .

a. If the default value is not empty, this is enough indication that the "preceding dot key" is intended for file association in all Windows NT version, then try to open the key name as mentioned by the value data, just says TheKeyNameMentioned.

a1)如果 TheKeyNameMentioned 下有子键 shell \ open \ command ,则测试是否存在此键的默认值指向的路径;如果路径存在,则存在与该扩展名关联的默认应用程序;如果该路径不存在,则默认应用程序是未知的.要获取文件扩展名说明,请查看默认值 TheKeyNameMentioned .要获取程序说明,​​首先,测试以下键是否包含等于EXE文件路径的值名称,即 HKCR \ Local Settings \ Software \ Microsoft \ Windows \ Shell \ MuiCache .如果存在,则查看值数据以获取文件描述;如果不存在,请直接使用GetFileVersionInfo()来获取文件描述.

a1) If there is subkeys shell\open\command under TheKeyNameMentioned, then test the existence of the path pointed by the default value of this key; if the path exists, there is a default application associated with the extension; if the path doesn't exists, the default application is unknown. To get the file extension description, look at the default value of TheKeyNameMentioned. To get the program description, first, test whether the following key contain a value-name equal to the EXE file path, that is HKCR\Local Settings\Software\Microsoft\Windows\Shell\MuiCache. If it is there, then look at the value data to get the file description; if it is not there, use GetFileVersionInfo() directly to get the file description.

a2)如果 TheKeyNameMentioned 下没有子键 shell \ open \ command ,则默认应用程序未知.要获取文件扩展名描述,请查看默认值 TheKeyNameMentioned .

a2) If there is no subkeys shell\open\command under TheKeyNameMentioned, then the default application is unknown. To get the file extension description, look at the default value of TheKeyNameMentioned.

b..在Windows Vista和更高版本上,当 [a] 点失败时,您需要进行其他检查.如果默认值为,请测试该键是否具有名为 OpenWithProgIDs 的子键.

b. On Windows Vista and later, when the point [a] fails, you need additional check. If the default value is empty, test whether the key has a subkey named OpenWithProgIDs.

  • 如果 OpenWithProgIDs 子项存在,请使用RegEnumValue()查找遇到的第一个符合条件的值名称,即 name <值名称的/em>必须指向与值名称相同名称的现有键(只是说 TheKeyNameMentioned .).如果存在 TheKeyNameMentioned ,则这足以表明先前的点密钥"旨在用于文件关联.阅读点 a1 a2 进行下一步.

  • If OpenWithProgIDs subkey exists, use RegEnumValue() to find the first encountered value name that meets the criteria, that is, the name of the value name must point to an existing key (just says TheKeyNameMentioned.) with the same name as the value name. If TheKeyNameMentioned exists, this is enough indication that the "preceding dot key" is intended for file association. Read point a1 and a2 for the next steps.

如果 OpenWithProgIDs 子项不存在,则默认应用程序未知.要获取文件扩展名描述,请查看默认值 TheKeyNameMentioned .

If OpenWithProgIDs subkey doesn't exist, the default application is unknown. To get the file extension description, look at the default value of TheKeyNameMentioned.

希望有帮助.:-)

这篇关于从注册表中读取已知的文件扩展名/类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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