How to get recommended programs related to file extension in C #

I want to get the path to programs related to the file extension, preferably through the Win32 API.

  • List of programs displayed in the "Open With" menu item
  • List of programs that are displayed according to the recommendations of the "Open with ..." dialog box.

UPD:

Suppose Office11 and Office12 are installed on my machine, the default program for .xls is Office 11. If you look at HKEY_CLASSES_ROOT \ Excel.Sheet.8 \ shell \ Open \ command, that is, the path to office11 is excel.exe, but when I right-click on a file, I can select office12 from the "Open with" menu. So where is this association stored?

I am using C #.

Thanks.

+8
c # windows file-association
source share
2 answers

I wrote a little procedure:

public IEnumerable<string> RecommendedPrograms(string ext) { List<string> progs = new List<string>(); string baseKey = @"Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\." + ext; using (RegistryKey rk = Registry.CurrentUser.OpenSubKey(baseKey + @"\OpenWithList")) { if (rk != null) { string mruList = (string)rk.GetValue("MRUList"); if (mruList != null) { foreach (char c in mruList.ToString()) progs.Add(rk.GetValue(c.ToString()).ToString()); } } } using (RegistryKey rk = Registry.CurrentUser.OpenSubKey(baseKey + @"\OpenWithProgids")) { if (rk != null) { foreach (string item in rk.GetValueNames()) progs.Add(item); } //TO DO: Convert ProgID to ProgramName, etc. } return progs; } 

which is called like this:

 foreach (string prog in RecommendedPrograms("vb")) { MessageBox.Show(prog); } 
+11
source share

Ever wanted to programmatically associate a file type in the system with your application, but didn’t like the idea of ​​digging through the registry yourself? If so, then this article and code is right for you.

File system association

+3
source share

All Articles