Quote Originally Posted by Drewster727 View Post
Is there a particular spot in the code I could just place a try catch statement to catch that issue rather than removing the ability to search for other user programs?

Thanks.

-Drew
Yeah you could just wrap each iteration of the loop through individual user's programs because if it fails for one item in that user's registry hive then it will fail for all of them so it doesn't make any sense to add the Try/Catch any further into the code.

Just try replacing this:

vb.net Code:
  1. Private Shared Function InternalGetInstalledPrograms(ByVal IncludeUpdates As Boolean, ByVal HklmPath As RegistryKey, ByVal HkuPath As RegistryKey) As List(Of InstalledProgram)
  2.         Dim ProgramList As New List(Of InstalledProgram)
  3.  
  4.         Dim ClassesKey As RegistryKey = HklmPath.OpenSubKey("Software\Classes\Installer\Products")
  5.  
  6.         '---Wow64 Uninstall key
  7.         Dim Wow64UninstallKey As RegistryKey = HklmPath.OpenSubKey("Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall")
  8.         ProgramList = GetUninstallKeyPrograms(Wow64UninstallKey, ClassesKey, ProgramList, IncludeUpdates)
  9.  
  10.         '---Standard Uninstall key
  11.         Dim StdUninstallKey As RegistryKey = HklmPath.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall")
  12.         ProgramList = GetUninstallKeyPrograms(StdUninstallKey, ClassesKey, ProgramList, IncludeUpdates)
  13.  
  14.         For Each UserSid As String In HkuPath.GetSubKeyNames
  15.             '---HKU Uninstall key
  16.             Dim CuUnInstallKey As RegistryKey = HkuPath.OpenSubKey(UserSid & "\Software\Microsoft\Windows\CurrentVersion\Uninstall")
  17.             ProgramList = GetUninstallKeyPrograms(CuUnInstallKey, ClassesKey, ProgramList, IncludeUpdates)
  18.             '---HKU Installer key
  19.             Dim CuInstallerKey As RegistryKey = HkuPath.OpenSubKey(UserSid & "\Software\Microsoft\Installer\Products")
  20.             ProgramList = GetUserInstallerKeyPrograms(CuInstallerKey, HklmPath, ProgramList)
  21.         Next
  22.  
  23.         'Close the registry keys
  24.         Try
  25.             HklmPath.Close()
  26.             HkuPath.Close()
  27.         Catch ex As Exception
  28.             Debug.WriteLine("Error closing registry key - " & ex.Message)
  29.         End Try
  30.  
  31.         'Sort the list alphabetically and return it to the caller
  32.         ProgramList.Sort()
  33.         Return ProgramList
  34.     End Function

with this:

vb.net Code:
  1. Private Shared Function InternalGetInstalledPrograms(ByVal IncludeUpdates As Boolean, ByVal HklmPath As RegistryKey, ByVal HkuPath As RegistryKey) As List(Of InstalledProgram)
  2.         Dim ProgramList As New List(Of InstalledProgram)
  3.  
  4.         Dim ClassesKey As RegistryKey = HklmPath.OpenSubKey("Software\Classes\Installer\Products")
  5.  
  6.         '---Wow64 Uninstall key
  7.         Dim Wow64UninstallKey As RegistryKey = HklmPath.OpenSubKey("Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall")
  8.         ProgramList = GetUninstallKeyPrograms(Wow64UninstallKey, ClassesKey, ProgramList, IncludeUpdates)
  9.  
  10.         '---Standard Uninstall key
  11.         Dim StdUninstallKey As RegistryKey = HklmPath.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall")
  12.         ProgramList = GetUninstallKeyPrograms(StdUninstallKey, ClassesKey, ProgramList, IncludeUpdates)
  13.  
  14.         For Each UserSid As String In HkuPath.GetSubKeyNames
  15.             Try
  16.                 '---HKU Uninstall key
  17.                 Dim CuUnInstallKey As RegistryKey = HkuPath.OpenSubKey(UserSid & "\Software\Microsoft\Windows\CurrentVersion\Uninstall")
  18.                 ProgramList = GetUninstallKeyPrograms(CuUnInstallKey, ClassesKey, ProgramList, IncludeUpdates)
  19.                 '---HKU Installer key
  20.                 Dim CuInstallerKey As RegistryKey = HkuPath.OpenSubKey(UserSid & "\Software\Microsoft\Installer\Products")
  21.                 ProgramList = GetUserInstallerKeyPrograms(CuInstallerKey, HklmPath, ProgramList)
  22.             Catch ex As Exception
  23.                 Debug.WriteLine("Error encountered in HKEY_USERS\" & UserSid & " : " & ex.Message)
  24.             End Try
  25.         Next
  26.  
  27.  
  28.         'Close the registry keys
  29.         Try
  30.             HklmPath.Close()
  31.             HkuPath.Close()
  32.         Catch ex As Exception
  33.             Debug.WriteLine("Error closing registry key - " & ex.Message)
  34.         End Try
  35.  
  36.         'Sort the list alphabetically and return it to the caller
  37.         ProgramList.Sort()
  38.         Return ProgramList
  39.     End Function

let me know how it goes