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?
Asked
Active
Viewed 7,431 times
9
-
2http://stackoverflow.com/questions/10927109/icon-for-click-once-app-in-add-or-remove-programs – Karthik Nov 06 '12 at 05:42
-
Great..Post what worked for you instead of posting the link..:) – Karthik Nov 06 '12 at 06:49
2 Answers
3
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());
}
}
}

Community
- 1
- 1

ManjuVijayan
- 338
- 1
- 5
- 19
-
1I tried this solution, but it doesn't change the image shown at the installation window (like in the screenshot of the opening post). Does someone have a solution for that as well? – Peter van Kekem Jan 19 '15 at 13:20
1
Setup: Visual Studio Enterprise 2015, WPF, C#
- Go to Solution Explorer
- Right-click on your ProjectName then click 'Properties'.
- Click Application as shown below. Remember your icon name.
- Click 'Publish' on the left column.
- Click 'Options...' button on the right.
- 'Publish Options' window should pop up as shown below. Remember what's in the 'Product name:' field. In the example below, it's "MyProductName"
- 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
}
}
}
- Call SetAddRemoveProgramsIcon in the constructor.
public MainViewModel()
{
SetAddRemoveProgramsIcon();
}

icernos
- 395
- 3
- 6
-
System.Windows.Forms.Application.StartupPath did not work for me. I had to use System.IO.Directory.GetCurrentDirectory() for my ClickOnce Installation as path for the Icon in Add and Remove Programms – halliballi Feb 24 '23 at 13:03