This is a continuation of my question here. I am creating an open with list for the type *.bmp.As per the answers for that question,I have created a list of the applications in the open with list from the registry keys.
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);
}
}
}
}
}
This method will return a list of application names like,
- Paint.Picture
- ehshell.exe
- MSPaint.exe
- ois.exe
- VisualStudio.bmp.10.0
- QuickTime.bmp
These are PrgIds and I can get the command that needs to be executed to open the specific application from
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;
}
Now How do I get the Application name that has to be displayed in the menu ? Each time that you start using a new application, Windows operating system automatically extract the application name from the version resource of the exe file, and stores it for using it later, in Registry key known as the 'MuiCache'. MUICache data is stored under HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache
but we cant guarentee that the application has been run at least once.Also we can directly get the desciption key from the version resources of the file but i have some trouble in splitting out the application path from commands like
%SystemRoot%\System32\rundll32.exe "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen %1
How could i get the name information ?
Below the list of my commands
- "C:\Windows\System32\rundll32.exe \"C:\Program Files\Windows Photo Viewer\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\""