
Originally Posted by
Drewster727
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:
Private Shared Function InternalGetInstalledPrograms(ByVal IncludeUpdates As Boolean, ByVal HklmPath As RegistryKey, ByVal HkuPath As RegistryKey) As List(Of InstalledProgram)
Dim ProgramList As New List(Of InstalledProgram)
Dim ClassesKey As RegistryKey = HklmPath.OpenSubKey("Software\Classes\Installer\Products")
'---Wow64 Uninstall key
Dim Wow64UninstallKey As RegistryKey = HklmPath.OpenSubKey("Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall")
ProgramList = GetUninstallKeyPrograms(Wow64UninstallKey, ClassesKey, ProgramList, IncludeUpdates)
'---Standard Uninstall key
Dim StdUninstallKey As RegistryKey = HklmPath.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall")
ProgramList = GetUninstallKeyPrograms(StdUninstallKey, ClassesKey, ProgramList, IncludeUpdates)
For Each UserSid As String In HkuPath.GetSubKeyNames
'---HKU Uninstall key
Dim CuUnInstallKey As RegistryKey = HkuPath.OpenSubKey(UserSid & "\Software\Microsoft\Windows\CurrentVersion\Uninstall")
ProgramList = GetUninstallKeyPrograms(CuUnInstallKey, ClassesKey, ProgramList, IncludeUpdates)
'---HKU Installer key
Dim CuInstallerKey As RegistryKey = HkuPath.OpenSubKey(UserSid & "\Software\Microsoft\Installer\Products")
ProgramList = GetUserInstallerKeyPrograms(CuInstallerKey, HklmPath, ProgramList)
Next
'Close the registry keys
Try
HklmPath.Close()
HkuPath.Close()
Catch ex As Exception
Debug.WriteLine("Error closing registry key - " & ex.Message)
End Try
'Sort the list alphabetically and return it to the caller
ProgramList.Sort()
Return ProgramList
End Function
with this:
vb.net Code:
Private Shared Function InternalGetInstalledPrograms(ByVal IncludeUpdates As Boolean, ByVal HklmPath As RegistryKey, ByVal HkuPath As RegistryKey) As List(Of InstalledProgram)
Dim ProgramList As New List(Of InstalledProgram)
Dim ClassesKey As RegistryKey = HklmPath.OpenSubKey("Software\Classes\Installer\Products")
'---Wow64 Uninstall key
Dim Wow64UninstallKey As RegistryKey = HklmPath.OpenSubKey("Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall")
ProgramList = GetUninstallKeyPrograms(Wow64UninstallKey, ClassesKey, ProgramList, IncludeUpdates)
'---Standard Uninstall key
Dim StdUninstallKey As RegistryKey = HklmPath.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall")
ProgramList = GetUninstallKeyPrograms(StdUninstallKey, ClassesKey, ProgramList, IncludeUpdates)
For Each UserSid As String In HkuPath.GetSubKeyNames
Try
'---HKU Uninstall key
Dim CuUnInstallKey As RegistryKey = HkuPath.OpenSubKey(UserSid & "\Software\Microsoft\Windows\CurrentVersion\Uninstall")
ProgramList = GetUninstallKeyPrograms(CuUnInstallKey, ClassesKey, ProgramList, IncludeUpdates)
'---HKU Installer key
Dim CuInstallerKey As RegistryKey = HkuPath.OpenSubKey(UserSid & "\Software\Microsoft\Installer\Products")
ProgramList = GetUserInstallerKeyPrograms(CuInstallerKey, HklmPath, ProgramList)
Catch ex As Exception
Debug.WriteLine("Error encountered in HKEY_USERS\" & UserSid & " : " & ex.Message)
End Try
Next
'Close the registry keys
Try
HklmPath.Close()
HkuPath.Close()
Catch ex As Exception
Debug.WriteLine("Error closing registry key - " & ex.Message)
End Try
'Sort the list alphabetically and return it to the caller
ProgramList.Sort()
Return ProgramList
End Function
let me know how it goes