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,
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
Right-click the image in Windows Explorer then mouse over "Open with" In the menu that opens, go to the bottom and select "Choose default program" Select the application of your choice under "Recommended Programs"
The most common ways are the following: Right Click > Open With > Choose Default Program This opens a dialog window with the option to browse any application to use for one-time only OR (by checking the appropriate checkbox) this would effectively set the default application for the selected filetype.
If you know the list of commands, then you can retrieve the description using the code given below
FileVersionInfo.GetVersionInfo(Path.Combine(Environment.SystemDirectory, "Notepad.exe"));
FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(Environment.SystemDirectory + "\\Notepad.exe");
// Print the file name and version number.
Console.WriteLine("File: " + myFileVersionInfo.FileDescription + '\n' +
"Version number: " + myFileVersionInfo.FileVersion);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With