InnoSetup 脚本打包及管理员权限设置

InnoSetup使用教程:InnoSetup打包安装

脚本详细

1. 定义变量

1 #define MyAppName "TranslationTool"
2 #define MyAppChineseName "翻译工具"
3 #define MyAppVersion "1.0"
4 #define MyAppPublisher "dotnetschool"
5 #define MyAppURL "https://dotnet-campus.github.io/"
6 #define MyAppExeName "TranslationTool.exe"

2. 初始化安装包设置

 1 [Setup]
 2 ; NOTE: The value of AppId uniquely identifies this application.
 3 ; Do not use the same AppId value in installers for other applications.
 4 ; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
 5 AppId={{AEDA7675-70DC-479E-B796-344517C2C954}
 6 AppName={#MyAppName}
 7 AppVersion={#MyAppVersion}
 8 ;AppVerName={#MyAppName} {#MyAppVersion}
 9 AppPublisher={#MyAppPublisher}
10 AppPublisherURL={#MyAppURL}
11 AppSupportURL={#MyAppURL}
12 AppUpdatesURL={#MyAppURL}
13 DefaultDirName={pf}\{#MyAppName}
14 DefaultGroupName={#MyAppChineseName}
15 OutputDir=C:\Users\10167\Desktop
16 OutputBaseFilename={#MyAppChineseName}
17 SetupIconFile=F:\GitHub\TranslationApiDemo\TranslationTool\TranslationTool\Images\bitbug_favicon.ico
18 Compression=lzma
19 SolidCompression=yes

其中,

  • AppId 程序标识
  • AppName 程序名称
  • AppVersion 版本号。生成默认版本号AppName+AppVersion
  • AppVerName 程序版本号。如果设置了AppVersion,则AppVerName会覆盖AppVersion值。
  • AppPublisher 发布者
  • AppPublisherURL、AppSupportURL、AppUpdatesURL 相关链接
  • DefaultDirName 默认安装目录
  • DefaultGroupName 默认开始菜单目录名
  • OutputDir 打包exe的生成目录,比如可以设置在桌面
  • OutputBaseFilename 打包exe的文件名称
  • SetupIconFile 设置打包exe的图标
  • Compression、SolidCompression 压缩相关

3. 启动文件和程序所有文件

1 [Files]
2 Source: "F:\GitHub\TranslationApiDemo\TranslationTool\TranslationTool\bin\Debug\TranslationTool.exe"; DestDir: "{app}"; Flags: ignoreversion
3 Source: "F:\GitHub\TranslationApiDemo\TranslationTool\TranslationTool\bin\Debug\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
4 ; NOTE: Don't use "Flags: ignoreversion" on any shared system files

忽略文件 Excludes: "*.bak,*.pdb,*.dll.config,*.ax,*\Log\*";

4. 图标

1 [Icons]
2 Name: "{group}\{#MyAppChineseName}"; Filename: "{app}\{#MyAppExeName}"
3 Name: "{group}\{cm:UninstallProgram,{#MyAppChineseName}}"; Filename: "{uninstallexe}"
4 Name: "{commondesktop}\{#MyAppChineseName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon

从上而下,分别是开始菜单中的启动快捷方式、开始菜单中的卸载快捷方式、桌面快捷方式

5. 直接启动

1 [Run]
2 Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#MyAppChineseName}}";Flags: nowait postinstall skipifsilent

在完成安装后,可以选择直接启动。

6. 添加Pascal代码

以上都只是innosetup提供的配置,如果需要定制注册表、卸载其它软件、定制界面、用户环境等,可以通过innosetup提供的一些事件来处理。如:

1 [code]
2 function InitializeSetup (): Boolean; 
3 begin
4    MsgBox('程序安装!', mbInformation, MB_OK);
5    Result := true;     
6 end; 

 

此处只介绍一些常用的字段参数,详细的可参考其它博客:https://blog.csdn.net/yiyihuazi/article/details/60323746https://www.cnblogs.com/langtianya/p/4285570.html

案例脚本:

 1 ; Script generated by the Inno Setup Script Wizard.
 2 ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
 3 
 4 #define MyAppName "TranslationTool"
 5 #define MyAppChineseName "翻译工具"
 6 #define MyAppVersion "1.0"
 7 #define MyAppPublisher "dotnetschool"
 8 #define MyAppURL "https://dotnet-campus.github.io/"
 9 #define MyAppExeName "TranslationTool.exe"
10 
11 [Setup]
12 ; NOTE: The value of AppId uniquely identifies this application.
13 ; Do not use the same AppId value in installers for other applications.
14 ; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
15 AppId={{AEDA7675-70DC-479E-B796-344517C2C954}
16 AppName={#MyAppName}
17 AppVersion={#MyAppVersion}
18 ;AppVerName={#MyAppName} {#MyAppVersion}
19 AppPublisher={#MyAppPublisher}
20 AppPublisherURL={#MyAppURL}
21 AppSupportURL={#MyAppURL}
22 AppUpdatesURL={#MyAppURL}
23 DefaultDirName={pf}\{#MyAppName}
24 DefaultGroupName={#MyAppChineseName}
25 OutputDir=C:\Users\10167\Desktop
26 OutputBaseFilename={#MyAppChineseName}
27 SetupIconFile=F:\GitHub\TranslationApiDemo\TranslationTool\TranslationTool\Images\bitbug_favicon.ico
28 Compression=lzma
29 SolidCompression=yes
30 
31 [Languages]
32 Name: "english"; MessagesFile: "compiler:Default.isl"
33 
34 [Tasks]
35 Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
36 
37 [Files]
38 Source: "F:\GitHub\TranslationApiDemo\TranslationTool\TranslationTool\bin\Debug\TranslationTool.exe"; DestDir: "{app}"; Flags: ignoreversion
39 Source: "F:\GitHub\TranslationApiDemo\TranslationTool\TranslationTool\bin\Debug\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
40 ; NOTE: Don't use "Flags: ignoreversion" on any shared system files
41 
42 [Icons]
43 Name: "{group}\{#MyAppChineseName}"; Filename: "{app}\{#MyAppExeName}"
44 Name: "{group}\{cm:UninstallProgram,{#MyAppChineseName}}"; Filename: "{uninstallexe}"
45 Name: "{commondesktop}\{#MyAppChineseName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
46 
47 [Run]
48 Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#MyAppChineseName}}";Flags: nowait postinstall skipifsilent
View Code

 

 设置安装包以管理员权限运行

如果安装包需要以管理员运行,在VS中设置程序以管理员权限启动之后,

在InnoSetup安装目录下,找到配置SetupLdr.e32文件,设置Manifest中的权限启动参数(与VisualStudio类似),操作如下:

下载Resource Hacker编译器,然后打开.e32文件,将其中权限相关参数,修改为管理员权限。

详细操作可参考:用inno setup制作管理员权限启动的安装包

案例截图

生成的安装包exe以及安装后桌面快捷方式

开始菜单中的快捷方式

posted @ 2018-11-26 20:05  唐宋元明清2188  阅读(5969)  评论(0编辑  收藏  举报