Uninstall installed prgrams on pc listed in Listview in vb.net,using RegistryKey

  • Thread starter Thread starter bAdRock17
  • Start date Start date
B

bAdRock17

Guest
How do i get Uninstall String for the selected item in Listview and then execute it

here's the code for listing all the installed programs in listview

'Location in Registry where all uninstall "settings" are stored
Dim ParentKey As RegistryKey =
Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall")
Dim name As String = ""
Dim installlocal As String = ""
Dim pub As String = ""
Dim Uninstall As String = ""
Dim count As Integer = 0 'Loop Counter
Dim softkey As String = "Software\Microsoft\Windows\CurrentVersion\Uninstall"
Dim ChildKey As RegistryKey 'Sub key of Parent key, to read necessary Uninstall properties


'Loop through each GUID listed
For Each child As String In ParentKey.GetSubKeyNames()


ChildKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(softkey).OpenSubKey(child)


If Not ChildKey Is Nothing Then 'If not empty, display inside ListView


name = ChildKey.GetValue("DisplayName", "").ToString()
installlocal = ChildKey.GetValue("InstallLocation", "").ToString()
pub = ChildKey.GetValue("Publisher", "").ToString()
Uninstall = ChildKey.GetValue("UninstallString", "").ToString()
End If
If Not String.IsNullOrEmpty(name) Then
Dim lst As New ListViewItem
lst.Text = name
lst.SubItems.Add(installlocal)
lst.SubItems.Add(pub)
lvApps.Items.Add(lst)






ReDim Preserve strUninstallStrings(count) 'Redim Array


If ChildKey.GetValue("UninstallString") IsNot Nothing Then 'Determine Uninstall Command(s)


strUninstallStrings(count) = ChildKey.GetValue("UninstallString") 'Store each command for each program


' lvApps.Items.Add(lst) 'Add ListItem


Else 'If No Uninstall Command Present, Identify it


strUninstallStrings(count) = "No Uninstall String"


End If
End If




count += 1 'Increment Counter for each item


Next


'Use LINQ to filter strUninstallStrings array, to only get valid programs with valid uninstall strings
NewUninstallStrArr = (From str In strUninstallStrings
Where Not {"No Uninstall String"}.Contains(str)).ToArray() 'New array to be used

Continue reading...
 
Back
Top