2010-05-25 13 views
6

È necessario ottenere un elenco di programmi installati sul computer locale con le icone dell'applicazione . Di seguito è riportato lo snippet di codice che sto utilizzando per ottenere l'elenco del programma installato e del percorso di directory installato.Ottenere un elenco di programmi installati con le icone dell'applicazione

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

Ora il problema è come posso ottenere l'icona dell'applicazione installata?

Grazie in anticipo.

+0

una cosa che il codice sopra riportato include anche aggiornamenti della finestra, come posso escludere quei programmi? – MUS

risposta

8

Per determinare se è un aggiornamento, ci sarà una chiave denominata IsMinorUpgrade. Questo è presente e impostato su 1 per gli aggiornamenti. Se è 0 o non presente, non è un aggiornamento.

Per ottenere un'icona da un file eseguibile, utilizzare questo codice:

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

sto usando il tasto "DisplayIcon" per ottenere l'icona rispetto al programma installato, ma ho ottenuto risultati diversi rispetto a Aggiungi Rimuovi Programma Utility disponibile nel pannello di controllo di WIN XP. Eventuali suggerimenti ? – MUS

+0

Questo è strano. Non ho idee, ma vedrò se riesco a fare ulteriori ricerche – Icemanind

0

Per estrarre l'icona di un'applicazione Windows installata prima abbiamo bisogno di capire la posizione dell'icona per l'applicazione Windows installata. Queste informazioni sono memorizzate nel Registro di sistema seguenti posizioni -

  1. chiave nome - HEKY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Uninstall Value - DisplayIcon
  2. nome chiave - HKEY_CLASSES_ROOT \ Installer \ Products {productID} Valore - ProductIcon

per maggiori dettagli e il codice per ottenere le icone delle applicazioni - http://newapputil.blogspot.in/2015/06/extract-icons-of-installed-windows_17.html

Problemi correlati