Windows 设置中的 VSTO 加载项图标
Icon of VSTO Add-In in Windows Setting
我使用 Visual Studio 中的发布功能为 VSTO Word 加载项创建 setup.exe。
在 Visual Studio 应用程序设置中,为项目分配了一个图标(图标和清单)。
遗憾的是,Windows 应用程序和功能设置中未显示此图标。只出现一个默认图标。
如何更改 Windows 应用程序和功能设置中使用的图标?
ClickOnce
安装程序需要额外的步骤来添加 windows 注册表项。 DisplayIcon
键应该在安装后添加,例如:
using System.Deployment.Application;
using Microsoft.Win32;
//Call this method as soon as possible
private static void SetAddRemoveProgramsIcon()
{
//Only execute on a first run after first install or after update
if (ApplicationDeployment.CurrentDeployment.IsFirstRun)
{
try
{
string iconSourcePath = Path.Combine(System.Windows.Forms.Application.StartupPath, "example.ico");
if (!File.Exists(iconSourcePath))
{
MessageBox.Show("We could not find the application icon. Please notify your software vendor of this error.");
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");
Console.WriteLine(myValue.ToString());
// Set this to the display name of the application. If you are not sure, browse to the registry directory and check.
if (myValue != null && myValue.ToString() == "Example Application")
{
myKey.SetValue("DisplayIcon", iconSourcePath);
break;
}
}
}
catch(Exception mye)
{
MessageBox.Show("We could not properly setup the application icons. Please notify your software vendor of this error.\r\n" + mye.ToString());
}
}
}
您可能会发现 'Add or Remove Programs' icon for a C# ClickOnce application 页面有帮助。
我使用 Visual Studio 中的发布功能为 VSTO Word 加载项创建 setup.exe。 在 Visual Studio 应用程序设置中,为项目分配了一个图标(图标和清单)。
遗憾的是,Windows 应用程序和功能设置中未显示此图标。只出现一个默认图标。 如何更改 Windows 应用程序和功能设置中使用的图标?
ClickOnce
安装程序需要额外的步骤来添加 windows 注册表项。 DisplayIcon
键应该在安装后添加,例如:
using System.Deployment.Application;
using Microsoft.Win32;
//Call this method as soon as possible
private static void SetAddRemoveProgramsIcon()
{
//Only execute on a first run after first install or after update
if (ApplicationDeployment.CurrentDeployment.IsFirstRun)
{
try
{
string iconSourcePath = Path.Combine(System.Windows.Forms.Application.StartupPath, "example.ico");
if (!File.Exists(iconSourcePath))
{
MessageBox.Show("We could not find the application icon. Please notify your software vendor of this error.");
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");
Console.WriteLine(myValue.ToString());
// Set this to the display name of the application. If you are not sure, browse to the registry directory and check.
if (myValue != null && myValue.ToString() == "Example Application")
{
myKey.SetValue("DisplayIcon", iconSourcePath);
break;
}
}
}
catch(Exception mye)
{
MessageBox.Show("We could not properly setup the application icons. Please notify your software vendor of this error.\r\n" + mye.ToString());
}
}
}
您可能会发现 'Add or Remove Programs' icon for a C# ClickOnce application 页面有帮助。