如何使用 Inno Setup 创建桌面图标

Posted

技术标签:

【中文标题】如何使用 Inno Setup 创建桌面图标【英文标题】:How to create a desktop icon with Inno Setup 【发布时间】:2015-11-22 14:18:23 【问题描述】:

我是 Inno Setup 的新手,我希望在 Inno Setup 中的可执行文件中添加一个桌面图标。该文件存储在

C:\Users\PycharmProjects\GIOTTOconverter\dist\giotto.ico

我尝试了几个例子,但没有结果。

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "GIOTTO"
#define MyAppVersion "1.0"
#define MyAppExeName "GIOTTO.exe"

[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId=48A8A469-1711-46FD-AC87-1596EF57C123
AppName=#MyAppName
AppVersion=#MyAppVersion
;AppVerName=#MyAppName #MyAppVersion
DefaultDirName=pf\#MyAppName
DefaultGroupName=#MyAppName
AllowNoIcons=yes
OutputBaseFilename=GiottoSetup
SetupIconFile=C:\Users\PycharmProjects\GIOTTOconverter\dist\giotto.ico
Compression=lzma
SolidCompression=yes

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
Name: "french"; MessagesFile: "compiler:Languages\French.isl"
Name: "italian"; MessagesFile: "compiler:Languages\Italian.isl"
Name: "spanish"; MessagesFile: "compiler:Languages\Spanish.isl"

[Tasks]
Name: "desktopicon"; Description: "cm:CreateDesktopIcon"; GroupDescription: "cm:AdditionalIcons"; Flags: unchecked
Name: "quicklaunchicon"; Description: "cm:CreateQuickLaunchIcon"; GroupDescription: "cm:AdditionalIcons"; Flags: unchecked; OnlyBelowVersion: 0,6.1

[Files]
Source: "C:\Users\PycharmProjects\GIOTTOconverter\dist\GIOTTO.exe"; DestDir: "app"; Flags: ignoreversion
Source: "C:\Users\PycharmProjects\GIOTTOconverter\dist\*"; DestDir: "app"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Icons]
Name: "group\#MyAppName"; Filename: "app\#MyAppExeName"
Name: "group\cm:UninstallProgram,#MyAppName"; Filename: "uninstallexe"
Name: "commondesktop\#MyAppName"; Filename: "app\#MyAppExeName"; Tasks: desktopicon
Name: "userappdata\Microsoft\Internet Explorer\Quick Launch\#MyAppName"; Filename: "app\#MyAppExeName"; Tasks: quicklaunchicon

[Run]
Filename: "app\#MyAppExeName"; Description: "cm:LaunchProgram,#StringChange(MyAppName, '&', '&&')"; Flags: nowait postinstall skipifsilent

【问题讨论】:

【参考方案1】:

[Files] section 中,您将giotto.ico 安装到应用程序文件夹(您可能希望仅在选择desktopicon 任务时安装图标)。

In [Icons] section, you create the desktop icon using the installed giotto.ico (when the desktopicon task is selected).

#define SourcePath "C:\Users\PycharmProjects\GIOTTOconverter\dist"
#define MyAppName "GIOTTO"
#define MyAppExeName "GIOTTO.exe"
#define MyAppIcoName "giotto.ico"

[Tasks]
Name: "desktopicon"; Description: "cm:CreateDesktopIcon"; \
    GroupDescription: "cm:AdditionalIcons"; Flags: unchecked

[Files]
Source: "#SourcePath\#MyAppExeName"; DestDir: "app"; Flags: ignoreversion
Source: "#SourcePath\#MyAppIcoName"; DestDir: "app"

[Icons]
Name: "userdesktop\#MyAppName"; Filename: "app\#MyAppExeName"; \
    IconFilename: "app\#MyAppIcoName"; Tasks: desktopicon

如果可执行文件(GIOTTO.exe)链接到相同的图标,则不需要单独安装图标。只需使用 EXE 文件中的图标:

#define SourcePath "C:\Users\PycharmProjects\GIOTTOconverter\dist"
#define MyAppName "GIOTTO"
#define MyAppExeName "GIOTTO.exe"

[Tasks]
Name: "desktopicon"; Description: "cm:CreateDesktopIcon"; \
    GroupDescription: "cm:AdditionalIcons"; Flags: unchecked

[Files]
Source: "#SourcePath\#MyAppExeName"; DestDir: "app"; Flags: ignoreversion

[Icons]
Name: "userdesktop\#MyAppName"; Filename: "app\#MyAppExeName"; \
    Tasks: desktopicon

【讨论】:

如果有人希望默认选中“创建桌面快捷方式”,只需从 CreateDesktopIcon 部分中删除 Flags: unchecked

以上是关于如何使用 Inno Setup 创建桌面图标的主要内容,如果未能解决你的问题,请参考以下文章

Inno setup更改桌面快捷方式图标

Inno Setup:将桌面图标复选框的默认值设置为 true

Inno Setup中怎么随语言定义桌面图标名?

inno setup打包的安装文件更换位置后图标改变了

inno setup 在win7下的开始菜单和桌面快捷方式问题

inno setup 创建桌面快捷方式的代码