Windows Develop Bookmark and Share   
 index > ClickOnce and Setup & Deployment Projects > customize icon for click once deployed application
 

customize icon for click once deployed application

Hi all,

How to change the icon for the deployed application in control panel. i have deployed the application through click once deployement (Visual Studio 2005).


Thanks in advance
jrv
  • Moved byYiChun ChenMSFTWednesday, April 29, 2009 9:47 AMDeployment issue (From:.NET Framework Setup)
  •  
revathij  Tuesday, April 28, 2009 4:05 AM
If you are talking about the icon displayed in Add/Remove programs (or Programs & Features in Vista), there is no way to change that to show your application's icon.

RobinS.
GoldMail.com
Visit my ClickOnce blog!
RobinDotNet  Thursday, April 30, 2009 5:37 PM
Yeah, I haven't seen any repercussions... Seems to work fine under XP and Vista.

        static void CheckUninstallIcon()
        {
            try
            {
                System.Diagnostics.Trace.Write("Checking Icon...");
                System.Diagnostics.Trace.Write(" ** IsNetworkDeployed: " + ApplicationDeployment.IsNetworkDeployed);
                System.Diagnostics.Trace.Write(" ** CurrentDeployment: " + ApplicationDeployment.CurrentDeployment);
                System.Diagnostics.Trace.Write(" ** IsFirstRun: " + ApplicationDeployment.CurrentDeployment.IsFirstRun);

                if (ApplicationDeployment.IsNetworkDeployed && ApplicationDeployment.CurrentDeployment != null &&
                    ApplicationDeployment.CurrentDeployment.IsFirstRun)
                {
                    System.Diagnostics.Trace.Write("Checking Token...");
                    string token = GetPublicKeyToken();
                    using (RegistryKey key = GetProgramGroupRegistryKey(token))
                    {
                        string icon = string.Format("{0},0", System.Reflection.Assembly.GetExecutingAssembly().Location);
                        if (icon != key.GetValue("DisplayIcon") as string)
                        {
                            System.Diagnostics.Trace.Write("Trying to set App Icon to: " + icon);
                            key.SetValue("DisplayIcon", icon);
                        }
                    }
                }
            }
            catch(Exception ex)
            {
                System.Diagnostics.Trace.Write("Unable to update Uninstall Icon: " + ex.Message);
            }
        }

        private static string GetPublicKeyToken()
        {
            ApplicationSecurityInfo asi = new ApplicationSecurityInfo(AppDomain.CurrentDomain.ActivationContext);
            byte[] pk = asi.ApplicationId.PublicKeyToken;
            StringBuilder pkt = new StringBuilder();
            for (int i = 0; i < pk.GetLength(0); i++)
            {
                pkt.Append(String.Format("{0:x}", pk[i]));
            }
            
            return pkt.ToString();
        }

        private static RegistryKey GetProgramGroupRegistryKey(string PublicKeyToken)
        {
            string searchString = "PublicKeyToken=" + PublicKeyToken;
            System.Diagnostics.Trace.Write("Looking for regkey: " + searchString);
            using (RegistryKey uninstallKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall", false))
            {
                if (uninstallKey != null)
                {
                    string[] appKeyNames = uninstallKey.GetSubKeyNames();

                    foreach (string appKeyName in appKeyNames)
                    {
                        System.Diagnostics.Trace.Write("Key: " + appKeyName);
                        RegistryKey appKey = uninstallKey.OpenSubKey(appKeyName, true);
                        System.Diagnostics.Trace.Write(appKey);
                        if (appKey != null)
                        {
                            string key = (string)appKey.GetValue("UninstallString");
                            if (key.Contains(searchString))
                                return appKey;
                            appKey.Close();
                        }
                    }
                }

                throw new Exception("App Not Found");
            }
        }


Hope that helps out there.. Not sure why ClickOnce doesn't do it automatically.
pjcast  Tuesday, August 04, 2009 4:03 PM
Excerpt from an existing thread

To have a custom icon displayed in your ClickOnce application the icon must be deployed with the application and the file must be specified as the value for the iconFile attribute in the .exe.manifest file.

In Visual Studio, this should be as easy as selecting the icon file for the Icon on the Application Property Page. (The icon file must be part of the main project.)

  • If the Build Action of the icon file is Embedded Resource, everything should just work. Visual Studio will automatically deploy the icon file separately and reference the icon file in the .exe.manifest file. It is a limitation of the ClickOnce runtime that the icon file must be deployed separately and not part of a resource dll.
  • If the icon file Build Action is Content and the Publish Status of the icon file on the Application Files Dialog (off the Publish Property Page) is Include, then everything should be okay.
  • If the icon file Build Action is set to Compile or None, it will not be deployed with the application and will not show up in the Start Menu when the application is installed.

I hope this information helps you solve your problem. Please let me know if it does not.



http://social.msdn.microsoft.com/Forums/en-US/vbide/thread/f00e1051-f3ef-46e1-b034-e82f14dc1444



Thanks, A.m.a.L | [Remember to click "mark as answered" when you get a correct reply to your question]
A.m.a.L - aditi.com - Think Product  Tuesday, April 28, 2009 4:56 AM
Hi Revathij,

I am moving this thread from Base ".NET FrameworkSetup" forum to the "ClickOnce and Setup & Deployment Projects" forum, since the issue is related to deployment. There are more deployment experts in the "ClickOnce and Setup & Deployment Projects" forum.

Thanks
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
YiChun Chen  Wednesday, April 29, 2009 9:46 AM
If you are talking about the icon displayed in Add/Remove programs (or Programs & Features in Vista), there is no way to change that to show your application's icon.

RobinS.
GoldMail.com
Visit my ClickOnce blog!
RobinDotNet  Thursday, April 30, 2009 5:37 PM
I've just gotten a request to replace the generic Icon with an application Icon for Add/Remove, and I see that I can alter the Registry to change that setting to another Icon... Is there a downside to changing the Icon?
pjcast  Tuesday, June 09, 2009 5:35 PM
If you can change hte registry without having a permission problem, give it a try. If it works, you're in like flynn.

Can you post back a link to the information on how to do that, for others trying to do the same thing?

RobinDotNet
Click here to visit my ClickOnce blog!
RobinDotNet  Friday, July 31, 2009 8:08 AM
Yeah, I haven't seen any repercussions... Seems to work fine under XP and Vista.

        static void CheckUninstallIcon()
        {
            try
            {
                System.Diagnostics.Trace.Write("Checking Icon...");
                System.Diagnostics.Trace.Write(" ** IsNetworkDeployed: " + ApplicationDeployment.IsNetworkDeployed);
                System.Diagnostics.Trace.Write(" ** CurrentDeployment: " + ApplicationDeployment.CurrentDeployment);
                System.Diagnostics.Trace.Write(" ** IsFirstRun: " + ApplicationDeployment.CurrentDeployment.IsFirstRun);

                if (ApplicationDeployment.IsNetworkDeployed && ApplicationDeployment.CurrentDeployment != null &&
                    ApplicationDeployment.CurrentDeployment.IsFirstRun)
                {
                    System.Diagnostics.Trace.Write("Checking Token...");
                    string token = GetPublicKeyToken();
                    using (RegistryKey key = GetProgramGroupRegistryKey(token))
                    {
                        string icon = string.Format("{0},0", System.Reflection.Assembly.GetExecutingAssembly().Location);
                        if (icon != key.GetValue("DisplayIcon") as string)
                        {
                            System.Diagnostics.Trace.Write("Trying to set App Icon to: " + icon);
                            key.SetValue("DisplayIcon", icon);
                        }
                    }
                }
            }
            catch(Exception ex)
            {
                System.Diagnostics.Trace.Write("Unable to update Uninstall Icon: " + ex.Message);
            }
        }

        private static string GetPublicKeyToken()
        {
            ApplicationSecurityInfo asi = new ApplicationSecurityInfo(AppDomain.CurrentDomain.ActivationContext);
            byte[] pk = asi.ApplicationId.PublicKeyToken;
            StringBuilder pkt = new StringBuilder();
            for (int i = 0; i < pk.GetLength(0); i++)
            {
                pkt.Append(String.Format("{0:x}", pk[i]));
            }
            
            return pkt.ToString();
        }

        private static RegistryKey GetProgramGroupRegistryKey(string PublicKeyToken)
        {
            string searchString = "PublicKeyToken=" + PublicKeyToken;
            System.Diagnostics.Trace.Write("Looking for regkey: " + searchString);
            using (RegistryKey uninstallKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall", false))
            {
                if (uninstallKey != null)
                {
                    string[] appKeyNames = uninstallKey.GetSubKeyNames();

                    foreach (string appKeyName in appKeyNames)
                    {
                        System.Diagnostics.Trace.Write("Key: " + appKeyName);
                        RegistryKey appKey = uninstallKey.OpenSubKey(appKeyName, true);
                        System.Diagnostics.Trace.Write(appKey);
                        if (appKey != null)
                        {
                            string key = (string)appKey.GetValue("UninstallString");
                            if (key.Contains(searchString))
                                return appKey;
                            appKey.Close();
                        }
                    }
                }

                throw new Exception("App Not Found");
            }
        }


Hope that helps out there.. Not sure why ClickOnce doesn't do it automatically.
pjcast  Tuesday, August 04, 2009 4:03 PM

Awesome. I'll give it a try. Thanks for the info!

RobinDotNet


Click here to visit my ClickOnce blog!
RobinDotNet  Wednesday, August 05, 2009 5:02 AM

You can use google to search for other answers

Custom Search

More Threads

• Publishing fails without error message
• How To Determine if we are in 'Repair' mode?
• Security debugging option problem
• tnsnames and setup projects
• Start menu location for ClickOnce application
• N00b - Deployment/Publishing
• word2pdf application run only on system installed with Office 2007
• problem width msimsp.exe tools
• Updating files during deployment
• Custom Installer for CAS