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?
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.
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.
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.
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.
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());
}
}
}
Setup: Visual Studio Enterprise 2015, WPF, C#
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
}
}
}
public MainViewModel()
{
SetAddRemoveProgramsIcon();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With