如何获得在C#文件扩展名关联节目推荐 [英] How to get recommended programs associated with file extension in C#

查看:209
本文介绍了如何获得在C#文件扩展名关联节目推荐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要得到与文件扩展名,preferably通过Win32 API的相关程序路径。

I want to get path to the programs that associated with file extension, preferably through Win32 API.


  1. 的出现在打开方​​式的程序列表菜单
    项目

  2. 建议在出现程序列表
    打开方式对话框。

UPD:

假设我有OFFICE11和OFFICE12安装在我的机器上,为.xls的默认程序是办公室11.如果看一下HKEY_CLASSES_ROOT \\ Excel.Sheet.8 \\壳\\打开\\命令有是OFFICE11 EXCEL.EXE的路径,但是当我用鼠标右键单击文件,我可以在打开方式菜单项选择OFFICE12。那么,是存储该关联?

Assume that i have office11 and office12 installed on my machine, default program for .xls is office 11. If look at HKEY_CLASSES_ROOT\Excel.Sheet.8\shell\Open\command there is a path to office11 excel.exe, but when i right click on file i can choose office12 in Open With menu item. So where is this association stored?

我使用C#。

感谢。

推荐答案

我写了一个小程序:

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 gets called like so:

foreach (string prog in RecommendedPrograms("vb"))
{
  MessageBox.Show(prog);
}

这篇关于如何获得在C#文件扩展名关联节目推荐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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