Tôi đã thử giải pháp trong câu hỏi Stack Overflow Custom icon for ClickOnce application in 'Add or Remove Programs' và Is there a way to change the icon of a ClickOnce application in 'Add or Remove Programs'?.'Thêm hoặc Xóa Chương trình' biểu tượng cho ứng dụng C# ClickOnce
Vì vậy, dưới đây là các triển khai của tôi. Cả hai người trong số họ biên dịch và không có ngoại lệ được ném khi mã được chạy. Tôi đang xuất bản các tệp thiết lập ClickOnce cho máy chủ web và sau đó cài đặt nó sau khi gỡ cài đặt từ máy tính. Khi tôi vào bảng điều khiển Thêm hoặc Xóa Chương trình, tôi vẫn thấy biểu tượng chung cho chương trình của mình. Ở khắp mọi nơi khác tôi không có vấn đề và biểu tượng của tôi chỉ hiển thị tốt.
/* METHOD ONE */
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, "forico4.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());
}
}
}
*/
/* METHOD TWO */
private static void SetAddRemoveProgramsIcon()
{
//only run if deployed
if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed
&& ApplicationDeployment.CurrentDeployment.IsFirstRun)
{
try
{
string iconSourcePath = Path.Combine(System.Windows.Forms.Application.StartupPath, "forico4.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() == "GoldMailAkamai")
{
myKey.SetValue("DisplayIcon", iconSourcePath);
break;
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
*/
Tại sao chúng ta không thể thực hiện việc này mà không cần hack registry? – HackSlash