自定义安装步骤
通过重写function InitializeSetup(): Boolean; 来实现自定义安装,
需要注意,此方法返回值如果为false,则将终止后续安装流程返回值
返回值约定为Result- 自动安装
在[Run]配置节点中加入需要安装的配置
例:
Filename: {tmp}\vc_redist_x86.exe; Parameters: "/q:a /c:""install /l /q"""; WorkingDir: {tmp}; Flags: skipifdoesntexist; StatusMsg: "Installing Microsoft Visual C++ Runtime ..."
自定义代码
在[Code]配置中添加自定义方法检测注册表是否存在
重要
根据 24K纯开源 的文章得知
64位系统需要将原本的HKLM改成HKLM64
//检测vs++2015
Result:=RegValueExists(HKLM64, 'SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\x86', 'Version');
//检测.netframeword4.5.2
Result:=RegValueExists(HKLM64, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full', 'Version');
- 定义退出安装程序的脚本
// ss
procedure ExitProcess(exitCode:integer);
external '[email protected] stdcall';
- 将资源释放到临时目录并调用
首先在[Files]中定义需要的资源
例:
Source: "C:\Users\ives\Desktop\Output\vc_redist_x86.exe"; DestDir: "{tmp}"; Flags: ignoreversion;
添加检测所需要的脚本 ,在[code]中定义
function IsVC2015():boolean;
var
version: Cardinal;
begin
Result:=RegValueExists(HKLM64, 'SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\x86', 'Version');
end;
最后在上面提到的InitializeSetup中调用
function InitializeSetup(): Boolean;
var Path:string;
ResultCode: Integer;
begin
//检测vc++2015
if (IsVC2015()=false) then
begin
if MsgBox('正在安装必备组件vc_redist_x86,请稍后……', mbConfirmation, MB_YESNO) = idYes then
begin
ExtractTemporaryFile('vc_redist_x86.exe');
Exec(ExpandConstant('{tmp}\vc_redist_x86.exe'), '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode);
end;
end;
Result:=true
end;