Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Application name to be displayed in open-with list?

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\""
like image 274
biju Avatar asked Aug 16 '12 05:08

biju


People also ask

How do I add an application to open with list?

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"

How do I add open with option?

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.


1 Answers

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);
like image 96
Amal Dev Avatar answered Oct 06 '22 19:10

Amal Dev