加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 使用应用程序图标获取已安装程序的列表

发布时间:2020-12-15 08:31:56 所属栏目:百科 来源:网络整理
导读:我需要在应用程序图标的本地计算机上获取已安装程序的列表.下面是用于获取已安装程序和已安装目录路径列表的代码段. /// summary /// Gets a list of installed software and,if known,the software's install path. /// /summary /// returns/returns priva
我需要在应用程序图标的本地计算机上获取已安装程序的列表.下面是用于获取已安装程序和已安装目录路径列表的代码段.
/// <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 = @"SOFTWAREMicrosoftWindowsCurrentVersionUninstall";
        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 knownn"; //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;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读