Skip to main content

Adding a Missing Icon to Program and Features for a Click Once install, VB.NET


 Click once is a great way to install win form applications within your organization. One issue I discovered recently is that the installed application’s icon does not appear in the Add/Remove programs (or Program and Features) dialog screen. This does not look very professional.

Searching the internet I found a work around here (this has both C# and VB.Net examples):
https://goo.gl/MpjXev

I made a few changes to the VB.Net code which I share below. A few issues I found that you should keep in mind:

  • Icon file should be set to Copy Always for the property Copy to Output Directory
  • Make sure your display name and product name match exactly as these are compared.
  • Icon is only updated on the first run of the application after install, so if you’re testing this code you will need to un-install before the next test/install.

Here’s my code, you will need to replace the calendar.ico text with your icon file and add the imports.

Imports System.Deployment.Application
   Imports Microsoft.Win32

   Sub SetAddRemoveProgramsIcon()
        Try
            'only run if deployed 
            If ApplicationDeployment.IsNetworkDeployed And ApplicationDeployment.CurrentDeployment.IsFirstRun Then

                Dim iconSourcePath As String = System.IO.Path.Combine(Application.StartupPath, "calendar.ico")

                If Not File.Exists(iconSourcePath) Then
                    Return
                End If

                Dim myUninstallKey As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall")
                Dim mySubKeyNames As String() = myUninstallKey.GetSubKeyNames()

                Dim i As Integer
                For i = 0 To mySubKeyNames.Length

                    Dim myKey As RegistryKey = myUninstallKey.OpenSubKey(mySubKeyNames(i), True)
                    Dim registryAppName As Object = myKey.GetValue("DisplayName")
                    Dim registryAppVersion As Object = myKey.GetValue("DisplayVersion")
                    If registryAppName <> Nothing And registryAppVersion <> Nothing And
                        registryAppName.ToString().StartsWith(Application.ProductName) And
                        registryAppVersion = ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString() Then

                        myKey.SetValue("DisplayIcon", iconSourcePath)
                        Exit For

                    End If
                Next

            End If

        Catch ex As Exception
            Throw
        End Try
    End Sub

Let me know if you have any questions.
Cheers,
Wade

Comments

Popular posts from this blog

My Art is Showing at the Renaissance Center!

Everyone, I have three images showing this month at the Renaissance Center in Wake Forest NC, below is a link. The show runs from March 7 to April 2. You can purchase my prints online at: https://wade-brooks.pixels.com/collections/recent Gallery Info here: https://www.wakeforestrencen.org/event/march-art-exhibit-reception-wake-forest-camera-club Cheers, Wade

What Next?

 It's time. It's time to do something completely different. Starting in November, I will be retired from Cree/Wolfspeed where I have worked for over 27 years. I feel it is time to move on. With that said, I'd like to do something. Something other than software or database development. I'm not really sure what form it will take, but I am open to suggestions. I know that I don't want to sit at a desk all day. I'd like to do something that helps others or the environment. It doesn't have to be related to photography, but could be. If you have any ideas, let me know. Cheers, Wade

Doing what you love and my 27 years at Cree/Wolfspeed

Working at the same company for 27 years is seen by some as bad for your career. Sure, I may have been able to make a little more money, but I do feel like I have mastered many of the skills I learned while working for Wolfspeed. And I don't think you truly understand a role until you have been submersed in it for a few years. When I started my career there were around 150 people working at Wolfspeed (then Cree Research). I started as a programmer, working on a shrink wrapped software application that controlled LED message signs. In my role, I worked on other software projects and was even involved in building an eight foot full color LED video screen. Very cool! Over the next twenty odd years, I have held many different roles and created some amazing things at Wolfspeed. I created the company's first public web page and also their first internal web portal. At last count, I have created over thirty five applications that are used for data parsing and analysis (and other needs...