[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;文章来源:https://www.toymoban.com/news/detail-787054.html
if(RegKeyExists(HKLM,'SOFTWARE\Microsoft\.NETFramework\Policy\v4.0')) = false then begin
dotNetMissing := true;
end;文章来源地址https://www.toymoban.com/news/detail-787054.html
到了这里,关于InnoSetup安装时先静默安装VS运行库并判断系统版本的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!