VC_redist.x86 detection

244 views
Skip to first unread message

m. e.l.

unread,
Jun 3, 2022, 6:45:13 AM6/3/22
to innosetup
Hi,

How to detect if VC_redist_x86 is already installed on system ?
(to avoid lauching that setup if not necessary...)

Thanks,
Mel

m. e.l.

unread,
Jun 3, 2022, 6:48:35 AM6/3/22
to innosetup
and a subsidiary question:
how to install it silently...

Thanks
Mel

Andrew Truckle

unread,
Jun 4, 2022, 2:07:07 AM6/4/22
to innosetup
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

Otomatic

unread,
Jun 4, 2022, 5:46:45 AM6/4/22
to innosetup
Hi,
There is also the registry keys:
[HKEY_CLASSES_ROOT\Installer\Dependencies\Microsoft.VS.VC_RuntimeMinimumVSU_x86,v14]
"Version"="14.32.31326"
"DisplayName"="Microsoft Visual C++ 2022 X86 Minimum Runtime - 14.32.31326"

and for 64bit
[HKEY_CLASSES_ROOT\Installer\Dependencies\Microsoft.VS.VC_RuntimeMinimumVSU_amd64,v14]
"Version"="14.32.31326"
"DisplayName"="Microsoft Visual C++ 2022 X64 Minimum Runtime - 14.32.31326"

m. e.l.

unread,
Jun 5, 2022, 3:43:11 AM6/5/22
to innosetup
Thanks to both of you.
I will do some testing with that code.
For running it without user action, it seems that /passive or /quiet are doing the job.

Mel

Reply all
Reply to author
Forward
0 new messages