Introduction to Inno Setup

Easy packing:

Choose to use the wizard to create a new script

Fill in the installation package name, installation version, installation package publisher, and related website of the installation package in the figure. The installation package name and version are required, and the remaining two are optional.

The first one is the application target basic folder can be selected, the second one is the name of the application folder, which is the newly created installation directory during installation. There are two options below, the first is whether the user can change the application folder, and the second is whether the application requires a folder. click next

Select the main execution file of the corresponding application and click Browse to select the main folder to be packaged. If you need to add other files, you can choose to add files or add folders below. You can see that there are two conditions that can be checked in the middle. One is whether to allow users to start the application after installation, and the second is whether the application has a main executable file, generally yes.

Whether to associate the file with the main execution file, the type name and extension of the application.

Create shortcuts in the start menu bar, whether to allow users to create desktop shortcuts

The license file, the display information file before installation, and the display information file after installation can be configured in this wizard, and can also be implemented by adding code in the script later, optional

Choose how to download, for whom to download, or ask users for a download mode.

Select language pack

Configure the output folder of the installation report, the installation package name, and logo, and set the password

Choose whether to use the #define compilation command, click Next to complete the script wizard

After clicking finish, you can choose to run the script on this basis, or not to run it, and make changes and additions to the script.

Introduction to Inno Setup:

1. Macro definition #define

Some customized global variables, for example: #define MyAppName "test" AppName={#MyAppName} when used below, need to add {#}.

2. Mainly used sections

1. The [Setup] section is used to set the basic information such as the name and author of the installation package. It should be noted that the id and name of different versions of the same program are the same, but different programs are different, and a random unique id can be generated in Tools-GenerateGUID.

2. [Languages] section, mainly to write the language pack of the program, select the language according to the previous wizard to generate

3. [Tasks], an optional section, which defines all user-definable tasks that the installer will perform during the installation process

4.[Files]节,定义安装程序要在用户系统上安装的文件,在这个段中有Source和DestDir两个主要属性,Source是指文件在设计者电脑上的位置,DestDir是指要安装在用户电脑上的位置。

5.[Registry],定义希望安装程序在用户系统上创建、修改或删除的注册表项/值

6.[Icons],定义安装程序在“开始”菜单栏和桌面上创建的快捷方式

7.[Run],可选节,在成功安装程序之后但在安装程序显示最终对话框之前要执行的任意数量的程序,比如安装后运行。

8.[Type],可选节,定义安装的类型,完全安装、简洁安装、自定义安装。例:

[Types]

Name: "full"; Description: "Full installation"

Name: "compact"; Description: "Compact installation"

Name: "custom"; Description: "Custom installation"; Flags: iscustom

9.[Components],可选节,受到[types]的影响,做组件选择,例如:

Name: "main"; Description: "Main Files"; Types: full compact custom; Flags: fixed

Name: "help"; Description: "Help Files"; Types: full

Name: "help\english"; Description: "English"; Types: full

Name: "help\dutch"; Description: "Dutch"; Types: full

  1. [Messages],更改显示在程序中的消息文本,例如:

ButtonNext=&Forward

将向导上的next修改为转发

  1. [Dirs]此可选部分定义除了用户选择的应用程序目录(自动创建)之外,安装程序要创建的任何其他目录。在主应用程序目录下创建子目录是本节的常见用途。

Name: "{app}\data"

Name: "{app}\bin"

({app}是指脚本项目所在的文件目录)

  1. [INI]此可选部分定义任何 .您希望安装程序在用户系统上设置的 INI 文件条目。

Filename: "MyProg.ini"; Section: "InstallSettings"; Flags: uninsdeletesection

13[Code]代码段,Pascal脚本

三、Pascal语言简介

基础语法:

赋值:”:=”

定义变量:var name:type;

if语句:

if 条件 then

begin

end else

begin

end;

(跟在if下的end后有else的话不用加分号)

for循环:

for i:=2 to n do

s:=s*i;

while语句:

while a>0 do

begin

a:=a-1;

end;

函数:

function name (形参名:形参类型):返回值类型;

(返回值直接是Result,不用自己定义变量作为返回值)

procedure name(形参名:形参类型);

换行:”#10#13”

  1. Setup event functions:

(事件函数,可以重载)

function InitializeSetup():Boolean;在初始化中调用,返回否则停止,否则返回是。可以使用这个函数做一些想到窗口显示之前做的事,比如判断用户是否安装了别的版本、安装环境是否满足条件。

procedure InitializeWizard();使用此事件函数可在启动时对向导页进行更改。不能为此使用 InitializeSetup 事件函数,因为在触发时,向导窗体尚不存在.

procedure DeinitializeSetup();在安装程序终止之前调用。请注意,即使用户在安装任何内容之前退出安装程序,也会调用此函数。

procedure CurStepChanged(CurStep:TSetupStep);您可以使用此事件功能执行自己的安装前和安装后任务。在实际安装开始之前使用 CurStep=ssInstall 调用,在实际安装完成后使用 CurStep=ssPostInstall 调用,在成功安装后安装程序终止之前使用 CurStep=ssDone调用。

procedure CurInstallProgressChanged(CurProgress,MaxProgress:Integer);可以使用此事件函数在安装程序提取文件、创建快捷方式、创建INI 条目和创建注册表项时监视进度。

function NextButtonClick(CurPageID:Integer):Boolean;点击next按钮时调用 。

function BackButtonClick(CurPageID:Integer):Boolean;点击back按钮调用。

procedure CancelButtonClick(CurPageID:Integer;var Cancle,Confirm:Boolean);点击取消按钮时调用。

function ShouldSkipPage(PageID:Integer):Boolean;向导调用此事件函数以确定是否应显示特定页面(由 PageID 指定)。如果返回 True,则将跳过该页面;如果返回 False,则可能会显示该页面。

procedure CurPageChanged(CurPageID:Integer);在显示新的向导页面后调用。

function CheckPassword(Password:String):Boolean;如果安装程序在 Pascal 脚本中找到密码查核事件函数,它会自动显示“密码”页并调用查核密码来检查密码。返回 True 接受密码,返回 False 拒绝密码。

function NeedRestart():Boolean;返回 True 指示安装程序在成功安装结束时提示用户重新启动系统,否则返回 False。

function UpdateReadyMemo(Space,NewLine,MemoUswrInfoInfo,MemoDirInfo,MemoTypeInfo,MemoComponentsInfo,MemoGroupInfo,MemoTasksInfo:String):String;如果安装程序在 Pascal 脚本中找到 UpdateReadyMemo 事件函数,则当“准备安装”向导页变为活动页时,将自动调用该函数。

function RegisterPreviousData(PreviousDataKey:Integer);若要存储自定义向导页上输入的用户设置,请在 Pascal 脚本中放置一个 RegisterPreviousData 事件函数,并在其中调用 SetPreviousData(PreviousDataKey, ...),每个设置一次。

function CheckSerial(Serial:String):Boolean;如果安装程序在 Pascal 脚本中找到 CheckSerial 事件功能,则序列号字段将自动出现在“用户信息”向导页上(必须在 [设置] 部分中使用 UserInfoPage=yes 启用该字段!返回 True 接受序列号,返回 False 拒绝序列号。

function GetCustomSetupExitCode:Integer;返回一个非零数字以指示安装程序返回自定义退出代码。仅当安装程序已成功运行到完成且退出代码为 0 时,才会调用此函数。

function PrepareToInstall(var NeedsRestart:Boolean):String;您可以使用此事件函数来检测和安装缺少的必备组件和/或关闭任何即将更新的应用程序.如果 CloseApplications 设置为 yes,则在安装程序检查正在使用的文件之前调用此函数。

function RegisterExtraCloseApplicationsResources;要注册额外的文件,如果 CloseApplications 设置为 yes,安装程序应检查是否正在使用,请在 Pascal 脚本中放置一个 RegisterExtraCloseApplicationsResources 事件函数,并在其中调用 RegisterExtraCloseApplicationsResource 每个文件一次。

五、Uninstall event functions:

function InitializeUninstall():Boolean;卸载程序

procedure InitializeUninstallProgressForm();使用此事件函数可在启动时更改进度窗体。不能为此使用 InitializeUninstall 事件函数,因为在触发时,进度窗体尚不存在。

procedure DeinitializeUninstall();

procedure CurUninstallStepChanged(CurUninstallStep:TUninstallStep);

function UninstallNeedRestart():Boolean;

六、如何使用DLLS和.NET依赖:

DLLS:

[Code]

function A(B: Integer): Integer;

external '<dllfunctionname>@<dllfilename>';

function A(B: Integer): Integer;

external '<dllfunctionname>@<dllfilename> <callingconvention>';

function A(B: Integer): Integer;

external '<dllfunctionname>@<dllfilename> <callingconvention> <options>';

callingconvention:调用约定,一般是stdcall

options:delayload,延迟加载DLL,在使用到该函数时加载;loadwithalteredsearchpath,指定应使用 Windows 标志LOAD_WITH_ALTERED_SEARCH_PATH加载 DLL,这实质上会导致加载程序在包含 DLL 的目录中搜索任何依赖 DLL;setuponly,指定仅当脚本从安装程序运行时,才应加载 DLL;uninstallonly,指定在卸载时加载。

.NET依赖:

首先要将.net的安装包文件放在.iss文件目录下,在[Files]段添加如下代码:

Source:"E:\Inno setup\PRO\ndp48-x86-x64-allos-enu.exe";DestDir:"{tmp}";Flags:ignoreversion,将文件添加在用户安装后的系统临时文件夹中,需要注意的是,他会在用户点击安装后才会将文件解压到临时文件中,而我们需要在向导未开始之前判断用户是否安装了,没有安装的话我们来进行安装,所以我们的代码需要将.NET的安装包进行解压放进系统临时文件夹中:

ExtractTemporaryFile('ndp48-x86-x64-allos- enu.exe');

此时我们可以调用Exec函数来运行.NET的安装文件:

Exec(ExpandConstant('{tmp}\ndp48-x86-x64-allos-enu.exe'),'','',SW_SHOWNORMAL,ewWaitUntilTerminated,rc);

Guess you like

Origin blog.csdn.net/qq_55687486/article/details/128703329