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

标签 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;
    }

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

提前致谢。

最佳答案

要确定它是否是更新,将有一个名为 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;
}

关于c# - 获取带有应用程序图标的已安装程序列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2907565/

相关文章:

c# - vb.net 中的 IComparer 问题,但在 C# 中工作相同

c# - 如何将按钮添加到 TabPage 的页眉?

c# - Winapp (c#) 调用 java 应用程序 -> 设置进度条

c# - 对不同的控件使用与事件相同的功能是不是一个坏主意?

c# - 在 .NET 的子类中扩展枚举定义

c# - 签署 WP7 项目的强名?

c# - 静态与非静态网络存储库

c# - 在动态 Lambda 表达式中获取 Count() 属性

vb.net - ADO - 解析字符串 URL 并使用参数

.net - UserPrincipal.FindByIdentity坚持 "There is no such object on the server."