Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I tried this code for finding the location of the installation folder during uninstallation from Add/remove programs. But when i am clicking on the program to uninstall in add/remove programs
the entry from the registry edit is removed and then coming to unistall overwritten method.
so always the the displaynme in the registry is not found. how do i resolve this.

VB
Public Overrides Sub Uninstall(ByVal savedState As System.Collections.IDictionary)
        Dim regKey As RegistryKey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall\")
        Dim location As String = FindByDisplayName(regKey, "Myapp")     
        MyBase.Uninstall(savedState)
    End Sub
    Private Function FindByDisplayName(ByVal parentKey As RegistryKey, ByVal name As String) As String

        Dim nameList As String() = parentKey.GetSubKeyNames()
        Dim i As Integer = 0
        While i < nameList.Length
            Dim regKey As RegistryKey = parentKey.OpenSubKey(nameList(i))
            Try
                If Not regKey.GetValue("DisplayName") = "" Then
                    If regKey.GetValue("DisplayName").ToString = name Then
                        MsgBox("found")
                        Return regKey.GetValue("InstallLocation").ToString
                    End If
                End If
            Catch ex As Exception
               
            End Try
            regKey.Flush()
            i += 1
        End While
        Return ""
    End Function


thanks
SK
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900