I am easily able to pull a list of applications on a system from the registry location of HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall but the list of applications I get back is much larger than the list shown in the Programs and Features.
For example on a test system I setup it shows 14 entries in Programs and Features but when I pull applications from the registry key shown above I get 35 applications back.
Is there an way to filter this list down to only the 14 entries shown in Programs and Features?
Here is my code in case it helps:
Class InstalledApps
Dim _AppList As New ArrayList
Sub New()
GetKeyValues("SOFTWARE\Microsoft\Windows\Currentversion\Uninstall", RegistryHive.LocalMachine)
GetKeyValues("SOFTWARE\Microsoft\Windows\Currentversion\Uninstall", RegistryHive.CurrentUser)
If CheckOSfor64() Then GetKeyValues("SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\", RegistryHive.LocalMachine)
_AppList.Sort()
End Sub
Sub New(SaveFileLocation As String)
GetKeyValues("SOFTWARE\Microsoft\Windows\Currentversion\Uninstall", RegistryHive.LocalMachine)
GetKeyValues("SOFTWARE\Microsoft\Windows\Currentversion\Uninstall", RegistryHive.CurrentUser)
If CheckOSfor64() Then GetKeyValues("SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\", RegistryHive.LocalMachine)
_AppList.Sort()
SaveFile(SaveFileLocation)
End Sub
Public ReadOnly Property getAppList As ArrayList
Get
Return _AppList
End Get
End Property
Private Sub SaveFile(Path As String)
Try
IO.File.Delete(Path)
Using newFile As StreamWriter = New StreamWriter(Path)
newFile.AutoFlush = True
For Each item As String In _AppList
If item.Contains("(KB") Then Continue For
newFile.WriteLine(item)
Next
End Using
Catch ex As Exception
End Try
End Sub
Private Function CheckOSfor64() As Boolean
Try
If System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE") = "AMD64" Then
Return True
Else
Return False
End If
Catch ex As Exception
Return False
End Try
End Function
Private Sub GetKeyValues(ByVal RegKey As String, ByVal Hive As Microsoft.Win32.RegistryHive)
Dim rk As RegistryKey = Nothing 'Main Keys
Dim sk As RegistryKey = Nothing 'Sub Keys
Dim name As String = String.Empty
Try
Select Case Hive
Case RegistryHive.CurrentUser
rk = Registry.CurrentUser.OpenSubKey(RegKey)
Case RegistryHive.LocalMachine
rk = Registry.LocalMachine.OpenSubKey(RegKey)
End Select
If rk Is Nothing Then Exit Sub
For Each skn As String In rk.GetSubKeyNames
If skn = Nothing Then Continue For
sk = rk.OpenSubKey(skn)
If sk.ValueCount = 0 Then Continue For
name = GetSubKeyValue(sk, "DisplayName")
'If empty skip
If name = String.Empty Then Continue For
'Check for Duplicate before adding
If Not _AppList.Contains(name) Then _AppList.Add(name)
Next
Catch ex As Exception
errorLogs.Add(ex)
Finally
If Not rk Is Nothing Then rk.Close()
If Not sk Is Nothing Then sk.Close()
rk = Nothing
sk = Nothing
End Try
End Sub
Private Function GetSubKeyValue(ByVal MainKey As RegistryKey, ByVal ValueName As String) As String
Try
If Not MainKey Is Nothing Then
Dim t As String = MainKey.GetValue(ValueName)
If t = Nothing Then Return String.Empty Else Return Trim(t)
Else
Return String.Empty
End If
Catch ex As Exception
Return String.Empty
End Try
End Function
End Class