简体   繁体   中英

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). How to achieve it?

Platform: Windows

Languages: 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. There is the IQueryAssociations interface, but it doesn't give you a whole lot of flexibility in how it queries. 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. That will give you the list of known file extensions.

For each HKEY_CLASSES_ROOT\\<ext> key, check for:

  1. a (Default) value that contains a non-blank string. If present, that is the file extension's 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). If none, check if the ProgID key has a CLSID subkey. If present, its (Default) value will be the CLSID of a COM object that handles everything associated with that ProgID. 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.

  2. a PersistentHandler subkey. If present, its (Default) value will be the CLSID of a COM object that handles that file extension. You can check the CLSID as needed.

  3. an OpenWithProgIds subkey. If present, then it will contain a list of ProgIDs that you can check as needed.

  4. an OpenWithList subkey. 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.

There are a few other possibilities (ShellEx keys, DDE keys, other Shell-related COM object keys, etc), but I think you see the point. There is potentially a LOT of digging to figure out which app handles a given file extension.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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