-1

This is a cosmetic issue but my application has a default icon on the control panel. Many other applications have custom icons.

My application does have custom icons for the menu and task bar.

How can the icon displayed on the Control Panel be changed using Visual Studio 2015 or later?

Update:

There has been a change in how Visual Studio creates installers. I'm not sure when it occurred, but 2015 definitely does not have a "deployment project". The majority of the hits on Google suggest going to the deployment project properties which does not exist under VS 2015 apps.

This was why I included the tag for visual-studio-2015. Sorry, not to have mentioned that in the original question. It would have been good information.

Using the registry is a possibility but the registry path mentioned, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, does not exist. It does sound kludgy to have the application check it's own icon in the registry all the time. It sounds like an installer function to me.

markjuggles
  • 466
  • 1
  • 4
  • 11
  • 2
    Possible duplicate of [How to change the icon in 'Add or Remove Programs'](https://stackoverflow.com/questions/16204889/how-to-change-the-icon-in-add-or-remove-programs) – Dmitry Aug 30 '17 at 15:45
  • You can get the detail from the below link. https://stackoverflow.com/a/16259374/4129621 – Arun Sharma Jun 18 '20 at 12:15

4 Answers4

2

A post on the Microsoft Developer Network provided an answer. It also modifies the registry. I enhanced it by removing hard-coded values for the application name and the icon file.

// These references are needed:
// using System.Reflection;
// using System.Deployment.Application;
// using System.IO;
// using Microsoft.Win32;

private static void SetAddRemoveProgramsIcon(string iconName)
{
    // only run if deployed
    if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed && ApplicationDeployment.CurrentDeployment.IsFirstRun)
    {
        try
        {
            string assemblyTitle="";

            object[] titleAttributes = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), true);
            if (titleAttributes.Length > 0 && titleAttributes[0] is AssemblyTitleAttribute)
            {
                assemblyTitle = (titleAttributes[0] as AssemblyTitleAttribute).Title;
            }

            string iconSourcePath = Path.Combine(System.Windows.Forms.Application.StartupPath, iconName);
            if (!File.Exists(iconSourcePath))
            {
                return;
            }

            RegistryKey myUninstallKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall");
            string[] mySubKeyNames = myUninstallKey.GetSubKeyNames();
            for (int i = 0; i < mySubKeyNames.Length; i++)
            {
                RegistryKey myKey = myUninstallKey.OpenSubKey(mySubKeyNames[i], true);
                object myValue = myKey.GetValue("DisplayName");
                if (myValue != null && myValue.ToString() == assemblyTitle)
                {
                    myKey.SetValue("DisplayIcon", iconSourcePath);
                    break;
                }
            }
        }
        catch (Exception) { }
    }

    return;
}

The original article by Robin Shahan is here: RobinDotNet

Lauren Rutledge
  • 1,195
  • 5
  • 18
  • 27
markjuggles
  • 466
  • 1
  • 4
  • 11
  • Instead of going through this much trouble why wouldn't you just look at the comment by Dmitry – boop_the_snoot Sep 01 '17 at 15:35
  • I did look at the the comment by Dmitry and many others. The solutions did not work for Visual Studio 2017. I'm sure they worked for some version at some point in time. – markjuggles Sep 02 '17 at 16:12
0

For WPF application we need to replace the following code

 string iconSourcePath = Path.Combine(System.Windows.Forms.Application.StartupPath, iconName);

Replace with below code

string iconSourcePath = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.Startup),  "TestIcon.ico");
Subrak
  • 139
  • 11
0

I know you want 2015 but others may be looking for this in newer versions, like I was.

In Visual Studio 2019 Community we can go to the properties panel for the main setup project and the top property is AddRemoveProgramsIcon.

Etherman
  • 1,777
  • 1
  • 21
  • 34
0

I have just come through this case today. I know it is old but will be useful for new seekers. To expose icon in Control Panel do the following:

  1. Make a folder in [solution Folder][Project Folder]\bin\debug\images
  2. Copy your icon in the new folder
  3. In Set Up project always refer to the icon in the new created folder.

Solved my problem easily