PDA

View Full Version : [ Vb.Net ] Nome e percorso Applicazioni Installate - Genymus


Genymus
21-03-2010, 21:05
Salve, ho usato il seguente pezzo di codice per verificare se un'applicazione era installata:
Imports Microsoft.Win32
...
Function OttieniProgrammi()
Dim Reg As RegistryKey = Registry.LocalMachine
Reg = Reg.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall")
For Each keyName As String In reg.GetSubKeyNames()
If (Reg.OpenSubKey(keyName).GetValue("DisplayName") Is Nothing) Then
ListBox1.Items.Add("Not] " & keyName)
Else
ListBox1.Items.Add("Els] " & Reg.OpenSubKey(keyName).GetValue("DisplayName").ToString())
End If
Next
Return True
End Function

Come posso ora ottenere il percorso di installazione del programma?
Grazie

Ps: Scartiamo subito la possibilità di fare una lista della cartella "Programmi"...


Grazie in anticipo per le risposte...
Genymus

MarcoGG
22-03-2010, 10:22
Possiamo completare un po' quel codice, ad esempio così :

> La Function :
Private Function ProgrammiInstallati() As List(Of String)

Dim L As New List(Of String)
Dim SoftwareKey As String = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"

Using RK As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(SoftwareKey)
For Each skName As String In RK.GetSubKeyNames
Using SK As Microsoft.Win32.RegistryKey = RK.OpenSubKey(skName)
Try
If SK.GetValue("DisplayName") <> Nothing Then
If SK.GetValue("InstallLocation") <> Nothing Then
L.Add(SK.GetValue("DisplayName") & " -> " & SK.GetValue("InstallLocation"))
Else
L.Add(SK.GetValue("DisplayName") & " -> PATH NON DISPONIBILE.")
End If
End If
Catch ex As Exception
L.Add(" - ERRORE - ")
End Try
End Using
Next
End Using

Return L

End Function

> Utilizzatore ( pulsante + ListBox ) :
ListBox1.Items.Clear()
For Each S As String In ProgrammiInstallati()
ListBox1.Items.Add(S)
Next

Su molti programmi veri e propri, che prevedono un uninstaller, funziona. Su librerie, driver ecc. vedo in lista molti "PATH NON DISPONIBILE".
Non ci ho studiato un granchè. Intanto vedi se può interessare come spunto... ;)

Genymus
22-03-2010, 16:12
Magnifico...
è vero, da molti "Non disponibili" ma per fortuna per i programmi che mi interessano, funziona.


Grazie Mille

MarcoGG
22-03-2010, 18:41
Magnifico...
è vero, da molti "Non disponibili" ma per fortuna per i programmi che mi interessano, funziona.


Grazie Mille

E' quello che conta. ;)
In ogni caso penso non ci possa esimere dall'entrare anche in qualche cartella ( comunque non certo uno scan esteso a tutta la cartella "Programmi" ), per avere un risultato completo...