I have created an uninstall list that is populated when a form loads. I want to add the ability to right click on the item and have an uninstall option. Below is the code that I'm using to show my Uninstall Manager so far.

Private Sub UninstallMgr_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        GetInstalledPrograms()
    End Sub

    Private Sub GetInstalledPrograms()
        With ListView1.Columns
            .Add("Software Name", 400) : .Add("Install Location", 300) : .Add("Publisher", 100)
        End With

        ListView1.View = View.Details ' Display Columns

        Dim Software As String = Nothing
        Dim SoftwareKey As String = "SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products"
        Using rk As RegistryKey = Registry.LocalMachine.OpenSubKey(SoftwareKey)
            For Each skName In rk.GetSubKeyNames
                Dim name = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skName).OpenSubKey("InstallProperties").GetValue("DisplayName")
                Dim installocation = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skName).OpenSubKey("InstallProperties").GetValue("InstallLocation")
                'InstallProperties
                Dim publisher = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skName).OpenSubKey("InstallProperties").GetValue("Publisher")
                Dim uninstallString = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skName).OpenSubKey("InstallProperties").GetValue("UninstallString")
                'Add the Software information to lstPrograms
                If name.ToString <> "" Then
                    'Declare new ListView Item
                    Dim list As New ListViewItem
                    'Set Text Property to Name of Software
                    list.Text = name.ToString
                    'Add Install Location
                    list.SubItems.Add(installocation.ToString)
                    'Add Publisher
                    list.SubItems.Add(publisher.ToString)
                    ' Add it to lstPrograms, a listview that will hold our Software List.
                    ListView1.Items.Add(list)
                End If

            Next
        End Using
    End Sub

Add a ContextMenuStrip and add items to it nd double click nd write the code. then click on ListView1 and set the ContextMenuStrip property to ur newly created contextmenustrip. then run the program, rightclick on the item. Rightclcik will be ther..

Okay,
In reference to the initial code that I posted. What would be the easiest way for my to reference the UninstallString that i Queried without having to do a hole new search?

when you lists the program add this code.

list.tag=uninstallstring

later you can directly retrieve the uninstall string from the items tag.
for ex. if u want to run uninstaller

uninstallpath=frmmain.listview1.selecteditems(0).tag
Shell(uninstallpath)

So the 0 in the ListView1.SelectedItems(0).tag.... Is that suppose to be statically 0 or do I need to put a variable there?

no. u need not use any variable. that is static. write it in the try catch function.

I ran the code you gave me but instead of the shell, I put MessageBox to see what it was returning. It was returning MSIEXE /I instead of MSIEXE /X . What am I doing wrong?

Help! An unhandled exception of type 'system.nullreferenceexception' occured in Uninstall manager.exe, where the For Each skName In rk.GetSubKeyNames is!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.