Comsci's answer (which Martin's answer adapted) is close but doesn't perform the version check correctly. (It will fail if there is a bump in the minor version and the build number resets to zero, for example.) Here's a corrected version of that answer, for both the 32-bit and 64-bit Visual Studio 2015-2019 packages.
I've found that the current 64-bit package breaks the runtime if it is already installed, so checking before installing it is necessary (until this is fixed by Microsoft). Edit: This was probably fixed in Visual Studio 16.10 (release notes).
As in the original answer, this is based on the Microsoft recommended way of determining whether the VC Redistributable is installed.
[Files]
Source: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Redist\MSVC\v142\vcredist_x86.exe; DestDir: {tmp}; Flags: deleteafterinstall ignoreversion
Source: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Redist\MSVC\v142\vcredist_x64.exe; DestDir: {tmp}; Flags: deleteafterinstall ignoreversion; Check: IsWin64
[Run]
Filename: {tmp}\vcredist_x86.exe; Parameters: /quiet /norestart; StatusMsg: "{#VCmsg32}"; Check: not VCRuntime32Installed
Filename: {tmp}\vcredist_x64.exe; Parameters: /quiet /norestart; StatusMsg: "{#VCmsg64}"; Check: IsWin64 and not VCRuntime64Installed
[Code]
function VCRuntime32Installed: Boolean;
var
required_major: Cardinal;
required_minor: Cardinal;
required_bld: Cardinal;
required_rbld: Cardinal;
major: Cardinal;
minor: Cardinal;
bld: Cardinal;
rbld: Cardinal;
key: String;
begin
required_major := 14;
required_minor := 29;
required_bld := 30037;
required_rbld := 0;
Result := False;
key := 'SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\X86';
if RegQueryDWordValue(HKLM32, key, 'Major', major) then begin
if RegQueryDWordValue(HKLM32, key, 'Minor', minor) then begin
if RegQueryDWordValue(HKLM32, key, 'Bld', bld) then begin
if RegQueryDWordValue(HKLM32, key, 'Rbld', rbld) then begin
Log('vcruntime (x86) version: ' + IntToStr(major) + '.' + IntToStr(minor) + '.' + IntToStr(bld) + '.' + IntToStr(rbld));
Result := (major > required_major) or ((major = required_major) and ((minor > required_minor) or ((minor = required_minor) and ((bld > required_bld) or ((bld = required_bld) and (rbld >= required_rbld))))))
end;
end;
end;
end;
end;
function VCRuntime64Installed: Boolean;
var
required_major: Cardinal;
required_minor: Cardinal;
required_bld: Cardinal;
required_rbld: Cardinal;
major: Cardinal;
minor: Cardinal;
bld: Cardinal;
rbld: Cardinal;
key: String;
begin
required_major := 14;
required_minor := 29;
required_bld := 30037;
required_rbld := 0;
Result := False;
key := 'SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\X64';
if RegQueryDWordValue(HKLM64, key, 'Major', major) then begin
if RegQueryDWordValue(HKLM64, key, 'Minor', minor) then begin
if RegQueryDWordValue(HKLM64, key, 'Bld', bld) then begin
if RegQueryDWordValue(HKLM64, key, 'Rbld', rbld) then begin
Log('vcruntime (x64) version: ' + IntToStr(major) + '.' + IntToStr(minor) + '.' + IntToStr(bld) + '.' + IntToStr(rbld));
Result := (major > required_major) or ((major = required_major) and ((minor > required_minor) or ((minor = required_minor) and ((bld > required_bld) or ((bld = required_bld) and (rbld >= required_rbld))))))
end;
end;
end;
end;
end;
here
however I don't agree with the answer since it installs the framework when the wizard starts, but IMO it should be run when you press the final Next button and the installation begins. I'll try to find the registry entries needed for this check. In the meantime take a look atthis post
. You need to useCheck
parameter for this. – TLama