How to Determine All Extensions Associated with an Application
Keywords: classes
Question:
I know how to get from Windows Registry the application that is associated with an extension, when I know the extension.Can you or anyone please tell me if and how I can get all the extensions that are associated with an application? I know the full path of the application and would like to know the extensions with which it is associated.
Answer:
Eeek.It is hard and messy. Basically have to check each registry key that starts with a "." under @REGCLASSES. Then it has to be traced back to the exe it is associated with. Then you have to make sure that you are not fooled by long/short file names.
Use RegQueryKey (singular (not RegQueryKeyS)) get the default value and decide what to do with it. It might be usable, or it might point to a common section for the exe.
PCMagazine's new utility "Freedom of Association" appears to do just that. When it is run, it goes through each HKCR hive and generates a list in memory of what extensions exist, what they are associated with, and then provides a number of displays so that you can scroll down and add/remove associations, etc. Not too hard to do in Winbatch, and it might be a nice utility to scan all file associations and generate a list of extensions without filetypes and filetypes without extensions.
Try this script snippet. It did the job in 7-8 seconds running from Popmenu. It should be cleaned up to ignore the "*" and "CLSID" keys, and perhaps more, but it seems to do what you what it to do.
For x=1 to 999 skey=RegQueryKey(@REGCLASSES, x) If skey == "" then break If Char2Num (skey) == 46 ; ascii code for "." IniWritePvt("Extensions", skey, RegQueryValue (@REGCLASSES, "%skey%[]"), "c:\assoc.ini") Else IniWritePvt("FileTypes", skey, RegQueryValue (@REGCLASSES, "%skey%[]"), "c:\assoc.ini") Endif next l_ext = IniItemizePvt ("Extensions", "c:\assoc.ini") l_types = IniItemizePvt ("FileTypes", "c:\assoc.ini") sType = AskItemList("Choose a File Type", l_types, @TAB, @SORTED, @SINGLE) l_results = "" for x = 1 to ItemCount(l_ext, @TAB) s_ext = ItemExtract (x, l_ext, @TAB) If IniReadPvt ("Extensions", s_ext, "", "c:\assoc.ini") == sType l_results = ItemInsert (s_ext, -1, l_results, @CR) Endif next Message ("Files Associated with %sType%", l_results)
Article ID: W13717Filename: Determine All Extensions Associated with an Application.txt