InnoSetup自动检测并安装.Net Framework

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
[Code]
 
function InitializeSetup: Boolean;
  var
    Path,tmppath:string ;      
    ResultCode: Integer;
    dotNetV2RegPath:string
    dotNetV2DownUrl:string;
    dotNetV2PackFile:string;
begin
 
  dotNetV2RegPath:='SOFTWARE\Microsoft\.NETFramework\Policy\v4.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/  

打赏
posted @   工程内业编程  阅读(6013)  评论(2编辑  收藏  举报
编辑推荐:
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
点击右上角即可分享
微信分享提示