获取带有应用程序图标的已安装程序列表

时间:2010-05-25 18:52:44

标签: c# vb.net winforms

我需要使用应用程序图标在本地计算机上获取已安装程序的列表。下面是用于获取已安装程序和已安装目录路径列表的代码段。

/// <summary>
    /// Gets a list of installed software and, if known, the software's install path.
    /// </summary>
    /// <returns></returns>
    private string Getinstalledsoftware()
    {
        //Declare the string to hold the list:
        string Software = null;

        //The registry key:
        string SoftwareKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
        using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(SoftwareKey))
        {
            //Let's go through the registry keys and get the info we need:
            foreach (string skName in rk.GetSubKeyNames())
            {
                using (RegistryKey sk = rk.OpenSubKey(skName))
                {
                    try
                    {
                        //If the key has value, continue, if not, skip it:
                        if (!(sk.GetValue("DisplayName") == null))
                        {
                            //Is the install location known?
                            if (sk.GetValue("InstallLocation") == null)
                                Software += sk.GetValue("DisplayName") + " - Install path not known\n"; //Nope, not here.
                            else
                                Software += sk.GetValue("DisplayName") + " - " + sk.GetValue("InstallLocation") + "\n"; //Yes, here it is...
                        }
                    }
                    catch (Exception ex)
                    {
                        //No, that exception is not getting away... :P
                    }
                }
            }
        }

        return Software;
    }

现在问题是我如何获得已安装的应用程序图标?

提前致谢。

2 个答案:

答案 0 :(得分:8)

要确定是否有更新,将会有一个名为IsMinorUpgrade的密钥。这存在并设置为1以进行更新。如果它是0或不存在,那么它不是更新。

要从可执行文件中获取图标,请使用以下代码:

<强> VB

Public Function IconFromFilePath(filePath As String) As Icon 
    Dim result As Icon = Nothing 
    Try 
        result = Icon.ExtractAssociatedIcon(filePath) 
    Catch ''# swallow and return nothing. You could supply a default Icon here as well 
    End Try 
    Return result 
End Function 

<强> C#

public Icon IconFromFilePath(string filePath)
{
    Icon result = null;
    try {
        result = Icon.ExtractAssociatedIcon(filePath);
    } catch { }
    return result;
}

答案 1 :(得分:0)

首先,要提取已安装的Windows应用程序的图标,我们需要确定已安装的Windows应用程序的图标位置。此信息存储在注册表中的以下位置 -

  1. 密钥名称 - HEKY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Uninstall 价值 - DisplayIcon
  2. 键名 - HKEY_CLASSES_ROOT \ Installer \ Products {productID} 价值 - ProductIcon
  3. 有关获取应用程序图标的更多详细信息和代码 - http://newapputil.blogspot.in/2015/06/extract-icons-of-installed-windows_17.html