0

I use the publish feature in Visual Studio to create a setup.exe for a VSTO Word Add-In. In the Visual Studio application settings, an icon (Icon and manifest) is assigned to the project.

Unfortunately, this icon is not displayed in the Windows Apps and Features Settings. There appears only a default icon. How can I change the Icon used in the Windows Apps and Features Settings?

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Dgo
  • 43
  • 5

1 Answers1

0

An additional step for adding a windows registry key is required for ClickOnce installers. The DisplayIcon key should be added after installation, for example:

using System.Deployment.Application;
using Microsoft.Win32;
//Call this method as soon as possible

private static void SetAddRemoveProgramsIcon()
{
    //Only execute on a first run after first install or after update
    if (ApplicationDeployment.CurrentDeployment.IsFirstRun)
    {
        try
        {
            string iconSourcePath = Path.Combine(System.Windows.Forms.Application.StartupPath, "example.ico");
            if (!File.Exists(iconSourcePath))
            {
                MessageBox.Show("We could not find the application icon. Please notify your software vendor of this error.");
                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");
                Console.WriteLine(myValue.ToString());
                // Set this to the display name of the application. If you are not sure, browse to the registry directory and check.
                if (myValue != null && myValue.ToString() == "Example Application")
                {
                    myKey.SetValue("DisplayIcon", iconSourcePath);
                    break;
                }
            }
        }
        catch(Exception mye)
        {
            MessageBox.Show("We could not properly setup the application icons. Please notify your software vendor of this error.\r\n" + mye.ToString());
        }
    }
}

You may find the 'Add or Remove Programs' icon for a C# ClickOnce application page helpful.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45