简体   繁体   English

在应用程序中注册的扩展名列表

[英]List of extensions registered with an application

For an application (for ex: excel.exe), I would like to know what all extensions (for ex: .xlt, .xlsx etc) are registered with application (excel.exe). 对于一个应用程序(例如:excel.exe),我想知道所有扩展名(例如:.xlt,.xlsx等)都已向应用程序(excel.exe)注册。 How to achieve it? 如何实现呢?

Platform: Windows 平台:Windows

Languages: C/C++/C# 语言:C / C ++ / C#

Unfortunately, file extension registrations can be a bit complex to work with. 不幸的是,文件扩展名注册的使用可能有点复杂。 There is no definitive API to extract the kind of information you are looking for. 没有确定的API可以提取您要查找的信息。 There is the IQueryAssociations interface, but it doesn't give you a whole lot of flexibility in how it queries. IQueryAssociations接口,但是它在查询方式上没有给您很大的灵活性。 It is more of a 1-to-1 query, but you are looking for a Many-to-1 query instead. 它更像是一对一查询,但是您正在寻找“多对一”查询。 So you will have to dig in the Registry directly for that information. 因此,您将必须直接在注册表中查找该信息。

Use RegOpenKeyEx() to open the HKEY_CLASSES_ROOT hive and enumerate all of its immediate subkeys with RegEnumKeyEx() , looking for key names that start with a period. 使用RegOpenKeyEx()打开HKEY_CLASSES_ROOT配置单元,并使用RegEnumKeyEx()枚举其所有直接子键,查找以句点开头的键名。 That will give you the list of known file extensions. 这将为您提供已知文件扩展名的列表。

For each HKEY_CLASSES_ROOT\\<ext> key, check for: 对于每个HKEY_CLASSES_ROOT\\<ext>键,请检查:

  1. a (Default) value that contains a non-blank string. (Default)值,其中包含非空白字符串。 If present, that is the file extension's ProgID. 如果存在,则为文件扩展名的ProgID。 You can open the HKEY_CLASSES_ROOT\\<ProgID> key and see if it has any shell\\<verb>\\command subkeys that contain the application path (there may be multiple <verb> values present, so you will have to enumerate them). 您可以打开HKEY_CLASSES_ROOT\\<ProgID>键,查看它是否具有包含应用程序路径的shell\\<verb>\\command子键(可能存在多个<verb>值,因此您必须枚举它们)。 If none, check if the ProgID key has a CLSID subkey. 如果没有,请检查ProgID项是否具有CLSID子项。 If present, its (Default) value will be the CLSID of a COM object that handles everything associated with that ProgID. 如果存在,则其(Default)值将是处理与该ProgID相关联的所有内容的COM对象的CLSID You can open the HKEY_CLASSES_ROOT\\CLSID\\<CLSID> key and check if it has an InprocHandler , InprocHandler32 , InprocServer or InprocServer32 subkey containing the full path to an EXE or DLL file that owns that COM object. 您可以打开HKEY_CLASSES_ROOT\\CLSID\\<CLSID>项,并检查它是否具有InprocHandlerInprocHandler32InprocServerInprocServer32子项,该子项包含拥有该COM对象的EXE或DLL文件的完整路径。

  2. a PersistentHandler subkey. PersistentHandler子项。 If present, its (Default) value will be the CLSID of a COM object that handles that file extension. 如果存在,则其(Default)值将是处理该文件扩展名的COM对象的CLSID You can check the CLSID as needed. 您可以根据需要检查CLSID。

  3. an OpenWithProgIds subkey. 一个OpenWithProgIds子项。 If present, then it will contain a list of ProgIDs that you can check as needed. 如果存在,则它将包含您可以根据需要检查的ProgID列表。

  4. an OpenWithList subkey. 一个OpenWithList子项。 If present, it will contain a list of registered app names. 如果存在,它将包含已注册应用名称的列表。 You can open the HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\<AppName> key to get the full path to each app. 您可以打开HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\<AppName>键以获取每个应用程序的完整路径。

There are a few other possibilities (ShellEx keys, DDE keys, other Shell-related COM object keys, etc), but I think you see the point. 还有其他几种可能性(ShellEx键,DDE键,其他与Shell相关的COM对象键等),但我想您明白了。 There is potentially a LOT of digging to figure out which app handles a given file extension. 可能需要进行大量挖掘,以确定哪个应用程序可以处理给定的文件扩展名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM