Skip to content

Commit 1dfb890

Browse files
Fix VC++ redistributable detection to avoid needless re-download (#4596) (#4598)
The previous detection passed a ProductCode to IsMsiProductInstalled, which expects an UpgradeCode. ProductCodes change with every redistributable build, so the check failed on all machines that didn't happen to have that exact build installed, causing the 18.5 MB vc_redist.x64.exe to be downloaded and re-run on every install. Switch primary detection to the registry method documented by Microsoft (HKLM\\SOFTWARE\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\<arch>), which is stable across installer builds and works for both x64 and arm64. Keep the verified x64 UpgradeCode as a fallback.
1 parent f390275 commit 1dfb890

File tree

1 file changed

+48
-6
lines changed

1 file changed

+48
-6
lines changed

InstallerExtras/CodeDependencies.iss

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,58 @@ begin
225225
Result := ShellExec('', ExpandConstant('{tmp}{\}') + 'netcorecheck' + Dependency_ArchSuffix + '.exe', Version, '', SW_HIDE, ewWaitUntilTerminated, ResultCode) and (ResultCode = 0);
226226
end;
227227
228+
function Dependency_IsVCRuntimeInstalled(const Arch: String; const Major, Minor, Bld: Cardinal): Boolean;
229+
var
230+
InstalledFlag, InstMajor, InstMinor, InstBld: Cardinal;
231+
Key: String;
232+
begin
233+
// Canonical VC++ runtime detection per Microsoft docs:
234+
// https://learn.microsoft.com/en-us/cpp/windows/redistributing-visual-cpp-files
235+
// The redistributable installer writes these values to both registry views,
236+
// so a plain HKLM read is correct from Inno Setup's 32-bit process.
237+
Key := 'SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\' + Arch;
238+
Result :=
239+
RegQueryDWordValue(HKLM, Key, 'Installed', InstalledFlag) and (InstalledFlag = 1) and
240+
RegQueryDWordValue(HKLM, Key, 'Major', InstMajor) and
241+
RegQueryDWordValue(HKLM, Key, 'Minor', InstMinor) and
242+
RegQueryDWordValue(HKLM, Key, 'Bld', InstBld) and
243+
((InstMajor > Major) or
244+
((InstMajor = Major) and (InstMinor > Minor)) or
245+
((InstMajor = Major) and (InstMinor = Minor) and (InstBld >= Bld)));
246+
end;
247+
228248
procedure Dependency_AddVC2015To2022;
249+
var
250+
Arch, Url: String;
251+
MinMajor, MinMinor, MinBld: Cardinal;
229252
begin
230253
// https://docs.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist
231-
if not IsMsiProductInstalled(Dependency_String('{91EE571B-0E8A-4C65-9EAF-2E2F5FC60C00}', '{91EE571B-0E8A-4C65-9EAF-2E2F5FC60C00}'), PackVersionComponents(14, 30, 30704, 0)) then begin
232-
Dependency_Add('vcredist2022' + Dependency_ArchSuffix + '.exe',
233-
'/passive /norestart',
234-
'Visual C++ 2015-2022 Redistributable (x64)' + Dependency_ArchTitle,
235-
Dependency_String('https://aka.ms/vc14/vc_redist.x64.exe', 'https://aka.ms/vc14/vc_redist.x64.exe'),
236-
'', False, False);
254+
MinMajor := 14;
255+
MinMinor := 30;
256+
MinBld := 30704;
257+
258+
if IsARM64 then begin
259+
Arch := 'arm64';
260+
Url := 'https://aka.ms/vc14/vc_redist.arm64.exe';
261+
end else begin
262+
Arch := 'x64';
263+
Url := 'https://aka.ms/vc14/vc_redist.x64.exe';
237264
end;
265+
266+
// Primary: registry-based detection (Microsoft's documented method, stable
267+
// across installer builds). Fallback: MSI UpgradeCode lookup for x64 only
268+
// (the x64 UpgradeCode {36F68A90-...} is verified; keeping a fallback helps
269+
// on unusual install states). See issue #4596 for the regression this
270+
// replaces, where a ProductCode was mistakenly used with IsMsiProductInstalled.
271+
if Dependency_IsVCRuntimeInstalled(Arch, MinMajor, MinMinor, MinBld) then Exit;
272+
if (Arch = 'x64') and IsMsiProductInstalled('{36F68A90-239C-34DF-B58C-64B30153CE35}',
273+
PackVersionComponents(MinMajor, MinMinor, MinBld, 0)) then Exit;
274+
275+
Dependency_Add('vcredist2022_' + Arch + '.exe',
276+
'/passive /norestart',
277+
'Visual C++ 2015-2022 Redistributable (' + Arch + ')',
278+
Url,
279+
'', False, False);
238280
end;
239281
240282

0 commit comments

Comments
 (0)