“添加或删除程序"中ClickOnce应用程序的自定义图标 [英] Custom icon for ClickOnce application in 'Add or Remove Programs'

查看:75
本文介绍了“添加或删除程序"中ClickOnce应用程序的自定义图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用法师创建的ClickOnce应用程序不显示在控制面板添加或删除程序中为Mage命令行参数指定的图标.

A ClickOnce application created using Mage is not showing the icon that was specified in for the Mage command-line parameter in control panel Add or Remove Programs.

我读了一些博客,例如:

I read some blogs, like:

如何在不编辑注册表项的情况下实现此目的?有可能吗?

How can I achieve this without editing registry keys? Is it possible?

推荐答案

如果不编辑注册表,则无法执行此操作,但是可以通过编程方式进行.您必须确保该图标包含在部署中.我们将程序集描述设置为与产品名称相同的字符串,因此我们可以通过搜索程序集描述来查看卸载字符串以找到正确的应用程序.这样,我们不必在此代码中对产品名称进行硬编码.

There's no way to do this without editing the registry, but you can do it programmatically. You have to be sure the icon is included in the deployment. We set our assembly description to the same string as our Product Name, so we can look through the uninstall strings for the right application by searching for the assembly description. This way, we don't have to hardcode the product name in this code.

        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, "youriconfile.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() == assemblyDescription)
                    {
                        myKey.SetValue("DisplayIcon", iconSourcePath);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                //log an error
            }
        }
    }

这篇关于“添加或删除程序"中ClickOnce应用程序的自定义图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆