Install VC_Redist Silently with InnoSetup | 一见知得 | Mr J Blog

Install VC_Redist Silently with InnoSetup

Mr J 555 0

First, download latest Visual C++ Redistributable installer from here:

Microsoft Visual C++ Redistributable latest supported downloads

In this example we will download x64: vc_redist.x64.exe

Rename it to VC_redist_x64.exe and place it inside \Redist\ folder.

In InnoSetup add this below [Files] section:

; VC++ redistributable runtime. Extracted only if needed, by checking if they are not installed
Source: "Redist\VC_redist_x64.exe"; DestDir: {tmp}; Check: VCRedistNeedsInstall; Flags: deleteafterinstall

Then add this below [Run] sections:

; Needed to install VC++ redistributables
Filename: "{tmp}\VC_redist_x64.exe"; StatusMsg: "Installing VC++ redistributables..."; Parameters: "/quiet /norestart"; Check: VCRedistNeedsInstall; Flags: waituntilterminated

Finally add this below [Code] section:

function VCRedistNeedsInstall: Boolean;
var 
  Version: String;
  RegKey: String;
begin
  RegKey := 'SOFTWARE\Microsoft\DevDiv\vc\Servicing\14.0\RuntimeMinimum';
  if IsWin64 then RegKey := 'SOFTWARE\Wow6432Node\Microsoft\DevDiv\vc\Servicing\14.0\RuntimeMinimum';
  if (RegQueryStringValue(HKEY_LOCAL_MACHINE, RegKey, 'Version', Version)) then
  begin
    // To check if VC 2015 are installed:
    // Is the installed version at least 14.0 ? (2015)
    // Visual C++ Redistributable for Visual Studio 2015 downloaded from:
    // https://www.microsoft.com/en-US/download/details.aspx?id=48145
    // Are versioned as 14.0.23026 in "Version" value
    Log('VC Redist Version check : found ' + Version);
    Result := (CompareStr(Version, '14.0.23026')<0);
    // To check if VC 2017 are installed:
    // Is the installed version at least 14.14 ? (2017)
    // Log('VC Redist Version check : found ' + Version);
    //Result := (CompareStr(Version, '14.14.26429.03')<0);
  end
  else 
  begin
    // Not even an old version installed
    Result := True;
  end;
  if (Result) then
  begin
    ExtractTemporaryFile('VC_redist_x64.exe');
  end;
end;
发表评论
表情 图片 链接 代码

分享
微信
微博
QQ