【发布时间】:2012-08-12 11:00:27
【问题描述】:
这是我的问题here 的延续。我正在为 *.bmp 类型创建一个打开列表。根据该问题的答案,我已经从注册表项中创建了一个打开列表中的应用程序列表。
public void RecommendedPrograms(string ext)
{
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())
{
string str=rk.GetValue(c.ToString()).ToString();
if (!progs.Contains(str))
{
progs.Add(str);
}
}
}
}
}
using (RegistryKey rk = Registry.CurrentUser.OpenSubKey(baseKey + @"\OpenWithProgids"))
{
if (rk != null)
{
foreach (string item in rk.GetValueNames())
progs.Add(item);
}
}
using (RegistryKey rk = Registry.ClassesRoot.OpenSubKey("." + ext + @"\OpenWithList"))
{
if (rk != null)
{
foreach (var item in rk.GetSubKeyNames())
{
if (!progs.Contains(item))
{
progs.Add(item.ToString());
}
}
}
}
using (RegistryKey rk = Registry.ClassesRoot.OpenSubKey("." + ext + @"\OpenWithProgids"))
{
if (rk != null)
{
foreach (string item in rk.GetValueNames())
{
if (!progs.Contains(item))
{
progs.Add(item);
}
}
}
}
}
此方法将返回一个应用程序名称列表,例如,
- 画.画
- ehshell.exe
- MSPaint.exe
- ois.exe
- VisualStudio.bmp.10.0
- QuickTime.bmp
这些是 PrgId,我可以从
获取打开特定应用程序需要执行的命令 public string GetRegisteredApplication(string StrProgID)
{
//
// Return registered application by file's extension
//
RegistryKey oHKCR;
RegistryKey oOpenCmd;
string command;
if (Environment.Is64BitOperatingSystem == true)
{
oHKCR = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.ClassesRoot, RegistryView.Registry64);
}
else
{
oHKCR = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.ClassesRoot, RegistryView.Registry32);
}
try
{
oOpenCmd = oHKCR.OpenSubKey(StrProgID + "\\shell\\open\\command");
if (oOpenCmd == null)
{
oOpenCmd = oHKCR.OpenSubKey("\\Applications\\" + StrProgID + "\\shell\\open\\command");
}
if (oOpenCmd != null)
{
command = oOpenCmd.GetValue(null).ToString();
oOpenCmd.Close();
}
else
{
return null;
}
}
catch (Exception ex)
{
return null;
}
return command;
}
现在如何获得必须在菜单中显示的应用程序名称? 每次您开始使用新的应用程序时,Windows 操作系统都会自动从 exe 文件的版本资源中提取应用程序名称,并将其存储在称为“MuiCache”的注册表项中以供以后使用。 MUICache 数据存储在 HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache 下
但我们不能保证应用程序至少运行过一次。我们也可以直接从文件的版本资源中获取描述密钥,但是我在从命令中拆分应用程序路径时遇到了一些麻烦
%SystemRoot%\System32\rundll32.exe "%ProgramFiles%\Windows 照片 Viewer\PhotoViewer.dll", ImageView_Fullscreen %1
如何获取姓名信息?
在我的命令列表下方
- "C:\Windows\System32\rundll32.exe \"C:\Program Files\Windows 照片查看器\PhotoViewer.dll\", ImageView_Fullscreen %1"
- "\"C:\Windows\eHome\ehshell.exe\"\"%1\""
- "C:\PROGRA~1\MIF5BA~1\Office14\OIS.EXE /shellOpen \"%1\""
- "\"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe\" /dde"
- "C:\Program Files (x86)\QuickTime\PictureViewer.exe \"%1\""
【问题讨论】: