2010-05-25 75 views
6

我需要獲得本地計算機上安裝的程序列表,其中應用程序圖標。以下是用於獲取已安裝程序列表和已安裝目錄路徑的代碼片段。獲取已安裝的應用程序圖標的程序列表

/// <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; 
    } 

現在的問題是我如何獲得安裝的應用程序圖標?

在此先感謝。

+0

還有一兩件事,上面的代碼還包括窗口更新,我如何排除這些程序? – MUS 2010-05-25 19:17:50

回答

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; 
} 
+0

我使用的是「DisplayIcon」鍵來獲取已安裝程序的圖標,但與WIN XP控制面板中的「添加刪除程序實用程序」相比,獲得了不同的結果。有什麼建議麼 ? – MUS 2010-05-29 19:21:45

+0

這是奇怪的。我沒有任何想法,但我會看看我是否可以研究更多 – Icemanind 2010-06-01 16:05:16

0

首先提取安裝的Windows應用程序的圖標我們需要找出已安裝的Windows應用程序的圖標位置。

  1. 鍵名 - - HEKY_LOCAL_MACHINE \ SOFTWARE \微軟\的Windows \ CurrentVersion \卸載 價值 - DisplayIcon
  2. 鍵名 - HKEY_CLASSES_ROOT \安裝\產品{的productID} 值此信息在以下位置存儲在註冊表中 - ProductIcon

更多細節和代碼來獲取應用程序圖標 - http://newapputil.blogspot.in/2015/06/extract-icons-of-installed-windows_17.html

相關問題