简体   繁体   English

在VS2010安装项目中为快捷方式设置正确的图标

[英]Setting correct icon for Shortcut in VS2010 Setup Project

I have a small app with a setup project. 我有一个带有安装项目的小应用程序。 If I create a shortcut to my Primary Output, then this gets a standard Win7 icon and not the icon specified in my exe's Application Icon? 如果我创建主输出的快捷方式,那么它将获得标准的Win7图标,而不是在exe的“应用程序图标”中指定的图标?

Whats the best way to make sure my desktop shortcut icon is the same icon as my exe? 确保我的桌面快捷方式图标与exe相同的最佳方法是什么? eg If I change the exe's icon then I'd like the Setup icon to change as well. 例如,如果我更改exe的图标,那么我也希望更改安装程序的图标。

If you set the icon for the shortcut you can set a primary output as source. 如果为快捷方式设置图标,则可以将主要输出设置为源。 In the file system editor of the setup project, click on the "(Icon)" combobox in the properties pane of the shortcut, then option "(Browse...)", button "Browse...". 在安装项目的文件系统编辑器中,单击快捷方式属性窗格中的“(Icon)”组合框,然后选择“(Browse ...)”选项,“ Browse ...”按钮。 You'll see this: 您会看到以下内容:

添加输出

Then add output and select the primary output of the exe. 然后添加输出并选择exe的主要输出。

You can add an icon from your target.exe file to the shortcut... in File System On Target Machine, browse to the shortcut in the folder you want to add the icon to (User's Desktop,etc). 您可以将target.exe文件中的图标添加到“目标计算机上的文件系统”中的快捷方式...中,浏览至要将图标添加到的文件夹中的快捷方式(用户的桌面等)。 Right click the shortcut and select Properties Window. 右键单击快捷方式,然后选择“属性窗口”。 You'll see an Icon line... click it, select Browse, then browse to Application Folder/yourExe.exe (change from ICON to Exe files) and say OK. 您将看到一个图标行...单击它,选择浏览,然后浏览到Application Folder / yourExe.exe(从ICON更改为Exe文件),然后说确定。 It will show you the icon from yourExe.exe that it has selected, say OK. 它将向您显示来自yourExe.exe的已选择图标,然后说“确定”。 You basically have to do the same thing for your Add/Remove Icon (appears in Control Panel/Uninstall)... properties page for your setup project. 基本上,您需要为安装项目的“添加/删除图标”(显示在“控制面板/卸载” ...)属性页中执行相同的操作。 You have to do it for all shortcuts in different folders (User's Desktop, User's Startup, etc.) All icons good now! 您必须对不同文件夹(用户的桌面,用户的启动等)中的所有快捷方式执行此操作。所有图标现在都很好!

To add to Gert's answer: make sure you build your project first. 要添加到Gert的答案中:确保先构建项目。 Otherwise the setup app will not see the icon. 否则,设置应用程序将看不到该图标。

Very simple way using IWshShortcut (works in .net 2 too): 使用IWshShortcut的非常简单的方法(也可以在.net 2中使用):

WshRuntimeLibrary.IWshShortcut MyShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(fullPathLnk);    
string iconLoc = MyShortcut.IconLocation; // <- example: "c:\icon.ico,0"

I use to check if iconLoc still exists, fix if not, you can use to find and read icon file, etc etc 我用来检查iconLoc是否仍然存在,修复是否不存在,可以用来查找和读取图标文件,等等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM