如何获取应用程序名称以打开列表显示?

bij*_*iju 6 c# registry wpf open-with

这是我的问题的延续在这里.我正在为类型*.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);
                    }
                }
            }
        }

    }
Run Code Online (Sandbox Code Playgroud)

此方法将返回应用程序名称列表,如

  • Paint.Picture
  • ehshell.exe
  • MSPaint.exe
  • ois.exe
  • VisualStudio.bmp.10.0
  • QuickTime.bmp

这些是PrgIds,我可以获取需要执行的命令来打开特定的应用程序

      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;
    }
Run Code Online (Sandbox Code Playgroud)

现在如何获取必须在菜单中显示的应用程序名称?每次开始使用新应用程序时,Windows操作系统都会自动从exe文件的版本资源中提取应用程序名称,并将其存储在稍后使用的注册表项(称为"MuiCache")中.MUICache数据存储在HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache下

但我们不能保证应用程序至少运行一次.我们也可以直接从文件的版本资源中获取desciption键,但是我在从命令这样的命令中拆分应用程序路径时遇到了一些麻烦

%SystemRoot%\ System32\rundll32.exe"%ProgramFiles%\ Windows Photo Viewer\PhotoViewer.dll",ImageView_Fullscreen%1

我怎么能得到名称信息?

在我的命令列表下面

  • "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 \""

Ama*_*Dev 2

如果您知道命令列表,则可以使用下面给出的代码检索描述

 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);
Run Code Online (Sandbox Code Playgroud)