|
正式会员享受无限制浏览网站功能和高速网盘下载,赶快加入本站吧!
您需要 登录 才可以下载或查看,没有账号?立即注册
x
运行安装程序时检查用户系统里面的安装的版本,如果版本低于你安装包里面的,则运行你安装包的的文件,否则跳过。
下面的代码中以 Microsoft Visual C++ 2010 Redistributable 作为例子。
如果文件很大,不便于打包到你的安装程序,你也可以让安装程序直接从网上下载,然后自动安装。下面的代码以 Microsoft .NET Framework 4 作为例子。
- [Files]
- Source: "download\isxdl.dll"; DestDir: {tmp}; Flags: dontcopy
- Source: "download\chinese.ini"; Flags: dontcopy
- [code]
- function isxdl_Download(hWnd: Integer; URL, Filename: PAnsiChar): Integer;
- external 'isxdl_Download@files:isxdl.dll stdcall';
- function isxdl_IsConnected: Integer;
- external 'isxdl_IsConnected@files:isxdl.dll stdcall';
- function isxdl_SetOption(Option, Value: PAnsiChar): Integer;
- external 'isxdl_SetOption@files:isxdl.dll stdcall';
- function vc2010_installed: Boolean;
- var
- VersionNum: String;
- begin
- result := false;
- if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\VisualStudio\10.0\VC\VCRedist\x86', 'Version', VersionNum) then
- begin
- Delete(VersionNum, 1, 1);
- if CompareVersion(VersionNum, '10.0.40219.1') >= 0 then // 检查 VC 2010 版本号是否大于 10.0.40219.1
- result := true;
- end;
- end;
- function netframework4_installed: Boolean;
- var
- iWert: Cardinal;
- begin
- result := false;
- if RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full', 'Install', iWert) then
- if iWert = 1 then
- result := true;
- end;
- procedure CurStepChanged(CurStep: TSetupStep);
- var
- ErrorCode: Integer;
- begin
- if CurStep = ssPostInstall then
- begin
- if not vc2010_installed then
- begin
- WizardForm.StatusLabel.Caption := '正在安装 Microsoft Visual C++ 2010 Redistributable,请稍候...';
- ExtractTemporaryFile('vcredist_x86.exe');
- Exec(ExpandConstant('{tmp}\vcredist_x86.exe'), '/passive', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ErrorCode);
- end;
- if not netframework4_installed then
- begin
- WizardForm.StatusLabel.Caption := '正在检查 Microsoft .NET Framework 运行环境,请稍候...';
- if MsgBox('警 告%n%n您的系统中尚未安装 Microsoft .NET Framework 4。%n安装程序可以自动下载并安装所需文件。%n您想要自动下载和安装 Microsoft .NET Framework 4 吗?', mbCriticalError, MB_YESNO or MB_DEFBUTTON2) = IDYES then
- if isxdl_IsConnected = 1 then
- begin
- ExtractTemporaryFile('chinese.ini');
- isxdl_SetOption('language', ExpandConstant('{tmp}\chinese.ini')); // 语言文件
- isxdl_SetOption('title', '你的安装程序');
- isxdl_SetOption('label', '下载');
- isxdl_SetOption('description', '下载 Microsoft .NET Framework');
- if isxdl_Download(0, 'http://download.microsoft.com/download/9/5/A/95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/dotNetFx40_Full_x86_x64.exe', PAnsiChar(ExpandConstant('{tmp}\dotNetFx40_Full_x86_x64.exe'))) = 1 then
- Exec(ExpandConstant('{tmp}\dotNetFx40_Full_x86_x64.exe'), '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ErrorCode);
- end
- else
- MsgBox('您目前没有 Internet 连接,请您以后从微软网站下载。', mbInformation, MB_OK);
- end;
- end;
- end;
复制代码
|
|