title: 'Add or Remove Programs' icon for a C# ClickOnce application
body: <p>I have tried the solution in Stack Overflow questions <em><a href="https://stackoverflow.com/questions/10927109/icon-for-click-once-app-in-add-or-remove-programs/11096813#11096813">Custom icon for ClickOnce application in 'Add or Remove Programs'</a></em> and <em><a href="https://stackoverflow.com/questions/13245056">Is there a way to change the icon of a ClickOnce application in 'Add or Remove Programs'?</a></em>.</p>
  
  <p>So, here are my implementations. Both of them compile and no exceptions are thrown when the code is run. I am publishing the ClickOnce setup files to a webserver and then installing it after uninstalling from computer. When I go to control panel <em>Add or Remove Programs</em>, I still see the generic icon for my program. Everywhere else I do not have issues and my icon shows up just fine.</p>
  
  <pre><code>/*  METHOD ONE */
  private static void SetAddRemoveProgramsIcon()
  {
      //Only run if deployed
      if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed &amp;&amp; ApplicationDeployment.CurrentDeployment.IsFirstRun)
      {
          try
          {
              Assembly code = Assembly.GetExecutingAssembly();
              AssemblyDescriptionAttribute asdescription =
                  (AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(code, typeof(AssemblyDescriptionAttribute));
              string assemblyDescription = asdescription.Description;
  
              //The icon is included in this program
              string iconSourcePath = Path.Combine(System.Windows.Forms.Application.StartupPath, "forico4.ico");
  
              if (!File.Exists(iconSourcePath))
                  return;
  
              RegistryKey myUninstallKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall");
              string[] mySubKeyNames = myUninstallKey.GetSubKeyNames();
              for (int i = 0; i &lt; mySubKeyNames.Length; i++)
              {
                  RegistryKey myKey = myUninstallKey.OpenSubKey(mySubKeyNames[i], true);
                  object myValue = myKey.GetValue("DisplayName");
                  if (myValue != null &amp;&amp; myValue.ToString() == "admin")
                  {
                      myKey.SetValue("DisplayIcon", iconSourcePath);
                      break;
                  }
              }
          }
          catch (Exception ex)
          {
              System.Windows.Forms.MessageBox.Show(ex.Message.ToString());
          }
      }
  }
  */
  
  /*  METHOD TWO */
  private static void SetAddRemoveProgramsIcon()
  {
      //only run if deployed
      if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed
         &amp;&amp; ApplicationDeployment.CurrentDeployment.IsFirstRun)
      {
          try
          {
              string iconSourcePath = Path.Combine(System.Windows.Forms.Application.StartupPath, "forico4.ico");
              if (!File.Exists(iconSourcePath))
                  return;
  
              RegistryKey myUninstallKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall");
              string[] mySubKeyNames = myUninstallKey.GetSubKeyNames();
              for (int i = 0; i &lt; mySubKeyNames.Length; i++)
              {
                  RegistryKey myKey = myUninstallKey.OpenSubKey(mySubKeyNames[i], true);
                  object myValue = myKey.GetValue("DisplayName");
                  if (myValue != null &amp;&amp; myValue.ToString() == "GoldMailAkamai")
                  {
                      myKey.SetValue("DisplayIcon", iconSourcePath);
                      break;
                  }
              }
          }
          catch (Exception ex)
          {
              Console.WriteLine(ex.ToString());
          }
      }
  }
  */
  </code></pre>