Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to change the icon of a ClickOnce application in 'Add or Remove Programs'?

I have one Windows application which is deployed using ClickOnce technology. Is there a way to change the icon of that application which is shown in the image?

Screenshot of the installer in action with a marker for the icon.

like image 219
ManjuVijayan Avatar asked Nov 06 '12 05:11

ManjuVijayan


People also ask

How to set icon in winform application?

Creating Desktop Applications Using Windows Forms You can change the icon in Visual Studio by opening the properties window for the form. You can then upload a new icon image to the icon field.

How do I remove ClickOnce from my project?

To uninstall a ClickOnce application, users can go to the Control Panel and launch the "Add or Remove Programs" application. In the "Change or Remove Programs" section, users then select the application to uninstall and click the Change/Remove button.

How do I manage updates for a ClickOnce application?

With a project selected in Solution Explorer, on the Project menu, click Properties. Click the Publish tab. Click the Updates button to open the Application Updates dialog box. In the Application Updates dialog box, make sure that the check box The application should check for updates is selected.

How do I add files to ClickOnce deployment?

On the File menu, click Open to open your application manifest. Select the Files tab. In the text box at the top of the tab, enter the directory that contains your application's files, and then click Populate. Your data file will appear in the grid.


2 Answers

The following code is what I used for solving the problem. I used Stack Overflow question Custom icon for ClickOnce application in 'Add or Remove Programs'.

    private static void SetAddRemoveProgramsIcon()
    {
        //only run if deployed
        if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed
             && 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, "hl772-2.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 < mySubKeyNames.Length; i++)
                {
                    RegistryKey myKey = myUninstallKey.OpenSubKey(mySubKeyNames[i], true);
                    object myValue = myKey.GetValue("DisplayName");
                    if (myValue != null && myValue.ToString() == "admin")
                    {
                        myKey.SetValue("DisplayIcon", iconSourcePath);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message.ToString());
            }
        }
    }
like image 152
ManjuVijayan Avatar answered Sep 26 '22 07:09

ManjuVijayan


Setup: Visual Studio Enterprise 2015, WPF, C#

  1. Go to Solution Explorer
  2. Right-click on your ProjectName then click 'Properties'.
  3. Click Application as shown below. Remember your icon name.

enter image description here

  1. Click 'Publish' on the left column.
  2. Click 'Options...' button on the right.
  3. 'Publish Options' window should pop up as shown below. Remember what's in the 'Product name:' field. In the example below, it's "MyProductName"

enter image description here

  1. Copy and paste the following code in your main class.


    private void SetAddRemoveProgramsIcon()
    {
        if (ApplicationDeployment.IsNetworkDeployed && ApplicationDeployment.CurrentDeployment.IsFirstRun)
        {
            try
            {
                var iconSourcePath = Path.Combine(System.Windows.Forms.Application.StartupPath, "MyIcon.ico");

                if (!File.Exists(iconSourcePath)) return;

                var myUninstallKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall");
                if (myUninstallKey == null) return;

                var mySubKeyNames = myUninstallKey.GetSubKeyNames();
                foreach (var subkeyName in mySubKeyNames)
                {
                    var myKey = myUninstallKey.OpenSubKey(subkeyName, true);
                    var myValue = myKey.GetValue("DisplayName");
                    if (myValue != null && myValue.ToString() == "MyProductName") // same as in 'Product name:' field
                    {
                            myKey.SetValue("DisplayIcon", iconSourcePath);
                        break;
                    }
                }
            }
            catch (Exception uhoh)
            {
                //log exception
            }
        }
    }

  1. Call SetAddRemoveProgramsIcon in the constructor.


    public MainViewModel()
    {
        SetAddRemoveProgramsIcon();
    }

like image 28
icernos Avatar answered Sep 22 '22 07:09

icernos