zoukankan      html  css  js  c++  java
  • InnoSetup自动检测并安装.Net Framework

    InnoSetup可在在脚本中插入[Code]代码段,其中的代码可以通过事件驱动,支持的主要事件如下:

    function InitializeSetup(): Boolean; ——安装程序初始化,返回值决定安装程序是否继续执行。
    function NextButtonClick(CurPageID: Integer): Boolean; ——点击下一步按钮,返回值决定安装程序是否继续执行。
    function BackButtonClick(CurPageID: Integer): Boolean; ——点击上一步按钮,返回值决定安装程序是否继续执行。
    function InitializeUninstall(): Boolean; ——卸载程序初始化,返回值决定卸载程序是否继续执行。
    ...
    从这些事件我们可以看到InitializeSetup()满足我们的要求,我们可以在这个时候去检查注册表或者是系统文件来判断客户机器上是否安装了.Net Framework,从而进行自动安装或者下载安装的操作。

    [Code]
    
    function InitializeSetup: Boolean; 
      var
        Path,tmppath:string ;       
        ResultCode: Integer;
        dotNetV2RegPath:string;  
        dotNetV2DownUrl:string; 
        dotNetV2PackFile:string; 
    begin
    
      dotNetV2RegPath:='SOFTWAREMicrosoft.NETFrameworkPolicyv4.0';
      dotNetV2DownUrl:='http://dl1sw.baidu.com/soft/9b/15910/Microsoft.NET.exe?version=585709662'; 
      dotNetV2PackFile:='{src}dotNetFx40_Full_x86_x64.exe';
      
    
      //先在注册表查找.net4.0是否存在
      if RegKeyExists(HKLM, dotNetV2RegPath) then  
      begin          
        Result := true; 
      end
    
      //如果注册表里面没有发现.net4.0
      else 
        begin  
          if MsgBox('系统检测到您没有安装.Net Framework4.0运行环境,是否立即安装?', mbConfirmation, MB_YESNO) = idYes then
           begin
              //和setup同级目录下的donet安装包
              Path := ExpandConstant(dotNetV2PackFile);
              //先抽取到临时目录
              tmppath :=  ExpandConstant('{tmp}dotNetFx40_Full_x86_x64.exe');
              ExtractTemporaryFile('dotNetFx40_Full_x86_x64.exe');
    
              msgbox(tmppath, mbConfirmation, MB_YESNO);
              Exec(tmppath, '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode);
    
              
              if(FileOrDirExists(tmppath)) then
              begin 
                Exec(tmppath, '/q', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode);
              if RegKeyExists(HKLM, dotNetV2RegPath) then
              begin
                Result := true;
              end 
            else 
            begin 
               MsgBox('未能成功安装.Net Framework4.0运行环境,系统将无法运行,本安装程序即将退出!',mbInformation,MB_OK); 
            end   
          end   
          else 
          begin 
            if MsgBox('软件安装目录中没有包含.Net Framework4.0的安装程序,是否立即下载后安装?', mbConfirmation, MB_YESNO) = idYes then 
            begin              
              Path := ExpandConstant('{pf}/Internet Explorer/iexplore.exe');
              Exec(Path, dotNetV2DownUrl , '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode);
              MsgBox('请安装好.Net Framework4.0环境后,再运行本安装包程序!',mbInformation,MB_OK); 
              Result := false; 
            end   
            else  
            begin   
              MsgBox('不下载安装.Net Framework4.0运行环境,系统将无法运行,本安装程序即将退出!',mbInformation,MB_OK);
              Result := false; 
            end         
          end       
        end        
        else     
        begin    
          MsgBox('没有安装.Net Framework2.0运行环境,系统将无法运行,本安装程序即将退出!',mbInformation,MB_OK); 
          Result := false;    
        end;
    
      end;
    
    end;
    

    参考链接1:http://blog.csdn.net/hualei/article/details/2628312

    参考链接2:http://zhoufoxcn.blog.51cto.com/792419/279243/  

  • 相关阅读:
    为什么大多数IOC容器使用ApplicationContext,而不用BeanFactory
    重温Java泛型,带你更深入地理解它,更好的使用它!
    看完了这篇,面试的时候人人都能单手撸冒泡排序!
    JAVA基础4---序列化和反序列化深入整理(Hessian序列化)
    VS Code 变身小霸王游戏机!
    equals()方法和hashCode()方法详解
    openFeign远程调用时使用Mybatis-plus的IPage接口进行返回分页数据失败的记录
    通过express快速搭建一个node服务
    UML 类图
    jdk命令行工具系列——检视阅读
  • 原文地址:https://www.cnblogs.com/lovelp/p/4437839.html
Copyright © 2011-2022 走看看