杉宫竹苑工作室

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2777|回复: 0

Inno Setup 检查用户系统环境安装包

[复制链接]
发表于 2017-3-6 18:13:06 | 显示全部楼层 |阅读模式

正式会员享受无限制浏览网站功能和高速网盘下载,赶快加入本站吧!

您需要 登录 才可以下载或查看,没有账号?立即注册

x

运行安装程序时检查用户系统里面的安装的版本,如果版本低于你安装包里面的,则运行你安装包的的文件,否则跳过。
下面的代码中以 Microsoft Visual C++ 2010 Redistributable 作为例子。
如果文件很大,不便于打包到你的安装程序,你也可以让安装程序直接从网上下载,然后自动安装。下面的代码以 Microsoft .NET Framework 4 作为例子。

  1. [Files]
  2. Source: "download\isxdl.dll"; DestDir: {tmp}; Flags: dontcopy
  3. Source: "download\chinese.ini"; Flags: dontcopy

  4. [code]
  5. function isxdl_Download(hWnd: Integer; URL, Filename: PAnsiChar): Integer;
  6. external 'isxdl_Download@files:isxdl.dll stdcall';

  7. function isxdl_IsConnected: Integer;
  8. external 'isxdl_IsConnected@files:isxdl.dll stdcall';

  9. function isxdl_SetOption(Option, Value: PAnsiChar): Integer;
  10. external 'isxdl_SetOption@files:isxdl.dll stdcall';

  11. function vc2010_installed: Boolean;
  12. var
  13.   VersionNum: String;
  14. begin
  15.   result := false;
  16.   if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\VisualStudio\10.0\VC\VCRedist\x86', 'Version', VersionNum) then
  17.     begin
  18.       Delete(VersionNum, 1, 1);      
  19.       if CompareVersion(VersionNum, '10.0.40219.1') >= 0 then       // 检查 VC 2010 版本号是否大于 10.0.40219.1
  20.         result := true;
  21.     end;
  22. end;

  23. function netframework4_installed: Boolean;
  24. var
  25.   iWert: Cardinal;
  26. begin
  27.   result := false;
  28.   if RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full', 'Install', iWert) then
  29.     if iWert = 1 then
  30.       result := true;
  31. end;

  32. procedure CurStepChanged(CurStep: TSetupStep);
  33. var
  34.   ErrorCode: Integer;
  35. begin
  36.   if CurStep = ssPostInstall then
  37.     begin
  38.     if not vc2010_installed then
  39.       begin
  40.       WizardForm.StatusLabel.Caption := '正在安装 Microsoft Visual C++ 2010 Redistributable,请稍候...';
  41.       ExtractTemporaryFile('vcredist_x86.exe');
  42.       Exec(ExpandConstant('{tmp}\vcredist_x86.exe'), '/passive', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ErrorCode);
  43.       end;
  44.     if not netframework4_installed then
  45.       begin
  46.       WizardForm.StatusLabel.Caption := '正在检查 Microsoft .NET Framework 运行环境,请稍候...';
  47.       if MsgBox('警 告%n%n您的系统中尚未安装 Microsoft .NET Framework 4。%n安装程序可以自动下载并安装所需文件。%n您想要自动下载和安装 Microsoft .NET Framework 4 吗?', mbCriticalError, MB_YESNO or MB_DEFBUTTON2) = IDYES then
  48.         if isxdl_IsConnected = 1 then
  49.           begin
  50.           ExtractTemporaryFile('chinese.ini');
  51.           isxdl_SetOption('language', ExpandConstant('{tmp}\chinese.ini'));  // 语言文件
  52.           isxdl_SetOption('title', '你的安装程序');
  53.           isxdl_SetOption('label', '下载');   
  54.           isxdl_SetOption('description', '下载 Microsoft .NET Framework');
  55.           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
  56.             Exec(ExpandConstant('{tmp}\dotNetFx40_Full_x86_x64.exe'), '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ErrorCode);
  57.           end
  58.         else
  59.           MsgBox('您目前没有 Internet 连接,请您以后从微软网站下载。', mbInformation, MB_OK);
  60.        end;
  61.     end;
  62. end;
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SgzyStudio

GMT+8, 2024-5-4 14:51 , Processed in 0.121885 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表