Ale*_*der 8 c# windows file-association
我想获得与文件扩展名相关的程序的路径,最好是通过Win32 API.
UPD:
假设我的办公室安装了office11和office12,.xls的默认程序是办公室11.如果查看HKEY_CLASSES_ROOT\Excel.Sheet.8\shell\Open \命令,有一个office11 excel.exe的路径,但是当我右键单击文件我可以在Open With菜单项中选择office12.那么这个关联存储在哪里?
我正在使用C#.
谢谢.
Lar*_*ech 13
我写了一个小例程:
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;
}
Run Code Online (Sandbox Code Playgroud)
它被调用如下:
foreach (string prog in RecommendedPrograms("vb"))
{
MessageBox.Show(prog);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6524 次 |
| 最近记录: |