InnoSetup安装时先静默安装VS运行库并判断系统版本

[Setup]

ArchitecturesInstallIn64BitMode=x64

[Files]

Source: "vc_redist.x64.exe"; DestDir: "{app}"; Check: NeedInstallVC9SP1
Source: "vc_redist.x86.exe"; DestDir: "{app}"; Check: NeedInstallVC9SP1

[Code]
var
  vc9SP1Missing: Boolean;

function NeedInstallVC9SP1(): Boolean;
begin
  Result := vc9SP1Missing;
end;
function InitializeSetup(): Boolean;
var 
  version: Cardinal;
begin
  if IsWin64 then begin
    // 64-bit OS                  {EF1EC6A9-17DE-3DA9-B040-686A1E8A8B04} 为 vc_redist.X64 GUID
    if RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{EF1EC6A9-17DE-3DA9-B040-686A1E8A8B04}', 'Version', version) = false then begin
      vc9SP1Missing := True;
    end;
  end
  else begin
    // 32-bit OS                  {BE960C1C-7BAD-3DE6-8B1A-2616FE532845} 为 vc_redist.X86 GUID
    if RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{BE960C1C-7BAD-3DE6-8B1A-2616FE532845}', 'Version', version) = false then begin
      vc9SP1Missing := True;
    end;
  end;
  Result := True;
end;

[Run]
//静默安装vs2015
Filename: "{app}\vc_redist.x64.exe"; Parameters: /q; StatusMsg: "Installing Microsoft Visual C++ Runtime …"; Flags: skipifdoesntexist;Check: NeedInstallVC9SP1  and IsWin64()
Filename: "{app}\vc_redist.x86.exe"; Parameters: /q; StatusMsg: "Installing Microsoft Visual C++ Runtime …"; Flags: skipifdoesntexist;Check: NeedInstallVC9SP1  and not IsWin64()

其中,运行库的GUID可以解压 vc_redist.exe,在文件0中搜索ProductCode,会搜到两个,我们需要 ProductCode 为 RollbackLogPathVariable = vcRuntimeAdditional 的那个GUID

目前仍有一个问题,即使系统已经安装了对应的vs版本,安装程序在完成安装之前仍会去运行vc_redist(这是使用了64位模式导致的:ArchitecturesInstallIn64BitMode,如果不判断系统版本就不会有这问题)

只判断x86注册表的示例代码:

#define MyVSGUID "{EFC21A37-5640-4BE1-981A-2FD3EDA1D893}";

[Files]

Source: "vc_redist.x86.exe"; DestDir: "{app}"; Check: NeedInstallVC9SP1

[Code]
var vc9SP1Missing: Boolean;
function NeedInstallVC9SP1(): Boolean;
begin
Result := vc9SP1Missing;
end;
function InitializeSetup(): Boolean;
var version: Cardinal;
begin                                                                           
if RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#MyVSGUID}', 'Version', version) = false then begin
vc9SP1Missing := true;
end;

//version值为0,表示未安装此运行库
//MsgBox('version值为:'+IntToStr(version),mbInformation, MB_OK);
result := true;

[Run]
Filename: "{app}\vc_redist.x86.exe"; Parameters: /q; StatusMsg: "正在安装vc++运行时..."; Flags: skipifdoesntexist;Check: NeedInstallVC9SP1

判断.net4是否安装

[code]

var  dotNetMissing: Boolean;

function NeedInstallDotNet(): Boolean;
begin
Result := dotNetMissing;
end;

if(RegKeyExists(HKLM,'SOFTWARE\Microsoft\.NETFramework\Policy\v4.0')) = false then begin
dotNetMissing := true;
end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值