For SoundSwitch, I needed to fix a bug where the installer wasn’t detecting correctly the version of VC Redist C++ installed.
As I found on Stack Overflow, each version has it’s own MSI key in the registry, but this is impossible to use since at each update of the VC Redist you need to find the new registry key and check for it.
However, I found this excellent post explaining where in the registry you can find if the wanted version is installed. The best part, the build is also present at the key given.
With that information at hand, I had all I needed to future proof my installer, and I’m happy to share with you the script I wrote for Inno Setup.
[Code]
function IsX64: boolean;
begin
Result := Is64BitInstallMode and (ProcessorArchitecture = paX64);
end;
procedure Explode(var Dest: TArrayOfString; Text: String; Separator: String);
var
i, p: Integer;
begin
i := 0;
repeat
SetArrayLength(Dest, i+1);
p := Pos(Separator,Text);
if p > 0 then begin
Dest[i] := Copy(Text, 1, p-1);
Text := Copy(Text, p + Length(Separator), Length(Text));
i := i + 1;
end else begin
Dest[i] := Text;
Text := '';
end;
until Length(Text)=0;
end;
function IsVcRedistInstalled(version: String; build: cardinal): boolean;
var
regBuildNumber: cardinal;
regKey: String;
regInstalled: cardinal;
regStringBuildNumber: String;
strArrayBuildNumber: TArrayOfString;
begin
Log('Check for VC Redist ' + version + ' with build ' + IntToStr(build));
if(IsX64()) then begin
regKey := 'SOFTWARE\WOW6432Node\Microsoft\VisualStudio\'+ version +'\VC\Runtimes\x64';
end else begin
regKey := 'SOFTWARE\Microsoft\VisualStudio\'+ version +'\VC\Runtimes\x86';
end;
RegQueryDWordValue(HKLM, regKey, 'Installed', regInstalled);
//Normal version installed, compare buildNumber
if(regInstalled = 1) then begin
Log('VC Redist ' + version + ' Installed');
RegQueryDWordValue(HKLM, regKey, 'Bld', regBuildNumber);
Result:= (regBuildNumber >= build);
Log('Detected VC Redist Build ' + IntToStr(regBuildNumber));
Exit;
end;
Log('VC Redist ' + version + ' not in default directory registry.')
//Check developer version
if(IsX64()) then begin
regKey := 'SOFTWARE\Wow6432Node\Microsoft\DevDiv\vc\Servicing\'+ version +'\RuntimeAdditional';
end else begin
regKey := 'SOFTWARE\Microsoft\DevDiv\vc\Servicing\'+ version +'\VC\RuntimeAdditional\x86';
end;
RegQueryDWordValue(HKLM, regKey, 'Install', regInstalled);
if(regInstalled <> 1) then begin
Result := false;
Exit;
end;
RegQueryStringValue(HKLM, regKey, 'Version', regStringBuildNumber);
Explode(strArrayBuildNumber, regStringBuildNumber, '.');
regBuildNumber := StrToInt(strArrayBuildNumber[2]);
Result:= (regBuildNumber >= build);
end;
2nd January 2017 at 20:58
Hi, did you post somewhere the [Run] part of the Inno Script?
3rd January 2017 at 13:39
Hello,
You can find an example here:
https://github.com/Belphemur/SoundSwitch/blob/dev/Installer/scripts/products/vcredist2015.iss
I’m using a full framework to check and download dependencies.
11th January 2018 at 15:57
Hello,
Very useful.
The regkeys when IsX64() is false seem false here.
I replace
\VC\VCRedist\x86
by
\VC\Runtimes\x86
in the first case and by
\RuntimeAdditional in the second case.
Regards.
11th January 2018 at 16:03
Hello Patrice,
Are you sure about the x86 version ?
I admit, I don’t have a 32Bit Windows (since a long time) and haven’t been able to try it. Only based it on previous found code.
If you can confirm me that you have tested it on 32 bits, I’ll glady change those regkeys.
11th January 2018 at 16:25
Yes. I have checked with a 32-bit Windows (with regedt32 and with my setup program).
11th January 2018 at 16:29
Great !
As soon as github is back online, I’ll fix the code.
Thank you for the correction !