You can run code like this:
function IsVCRedist32BitNeeded(): boolean;
var
Version: string;
Major, Minor, Bld, Rbld: Cardinal;
VCRuntimeInstalled: boolean;
begin
VCRuntimeInstalled := false; { Assume that VC Runtime is not installed }
Result := true;
{ Version number is: Major.Minor.Bld.Rbld }
{ Minimum valid version is: 14.14.26429.03 }
if (RegQueryDWordValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x86', 'Major', Major) and
RegQueryDWordValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x86', 'Minor', Minor) and
RegQueryDWordValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x86', 'Bld', Bld) and
RegQueryDWordValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x86', 'Rbld', Rbld) and
RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x86', 'Version', Version)) then
begin
VCRuntimeInstalled := true;
end
else if (RegQueryDWordValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\x86', 'Major', Major) and
RegQueryDWordValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\x86', 'Minor', Minor) and
RegQueryDWordValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\x86', 'Bld', Bld) and
RegQueryDWordValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\x86', 'Rbld', Rbld) and
RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\x86', 'Version', Version)) then
begin
VCRuntimeInstalled := true;
end;
if (VCRuntimeInstalled) then
begin
{ Is the installed version at least 14.14 ? }
Result :=
(ComparePackedVersion(
PackVersionComponents(Major, Minor, Bld, Rbld),
PackVersionComponents(14, 14, 26429, 3)) < 0);
if (Result) then
Log('Visual Studio Redist x86 is not already installed')
else
Log('Visual Studio Redist x86 Version : found ' + Version);
end;
end;
I call that function in InitializeWizard and cache it to a variable:
bVcRedist32BitNeeded := IsVCRedist32BitNeeded();
Then I add the relevant code to download the setup.
At the end I use CurStepChanged==ssPostInstall:
if (bVcRedist32BitNeeded) then
begin
if Exec(ExpandConstant(vcRedist32BitPath), '/install /passive /norestart', '',
SW_SHOW, ewWaitUntilTerminated, ResultCode) then begin
{ Handle success if necessary; ResultCode contains the exit code }
Log('VS Redist (32 bit) installer exit code = ' + IntToStr(ResultCode));
if ResultCode = 3010 then
begin
Log('Need restart');
bNeedsRestart := True;
end
else
if ResultCode <> 0 then
begin
MsgBox(
ExpandConstant('{cm:InstallFailed,Visual Studio x86 Redistributable}'),
mbInformation, MB_OK);
Abort();
end;
end
else begin
{ The execution failed for some reason }
Log('VS Redist (32 bit) installer exit code = ' + IntToStr(ResultCode));
MsgBox(SysErrorMessage(ResultCode), mbInformation, MB_OK);
Abort();
end;
end;
end;
Hope this helps