我可以轻松地从 HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall 的注册表位置中提取系统上的应用程序列表,但我返回的应用程序列表比程序和程序中显示的列表大得多特征。
例如,在我设置的一个测试系统上,它在程序和功能中显示了 14 个条目,但是当我从上面显示的注册表项中提取应用程序时,我得到了 35 个应用程序。
有没有办法将此列表过滤到仅显示在程序和功能中的 14 个条目?
这是我的代码以防万一:
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