InnoSetup - Check if visual studio 2010 crt redist is installed, if not then run installer

12,225

I follow the "official" MS way https://stackoverflow.com/a/199783/866333. Not exactly gone viral yet but it works for me.

See Inno Setup: Verify that .NET 4.0 is installed for working code to detect just one version.

This is the best example of the code I actually use: http://www.vincenzo.net/isxkb/index.php?title=.NET_-_Detect_framework

All the above targets the .NET framework. For VCRT I would extract the redistributable from VC2010 and have InnoSetup copy the contents over to the application's target install directory. That way system files don't get altered.

Share:
12,225
Marko29
Author by

Marko29

Updated on June 05, 2022

Comments

  • Marko29
    Marko29 almost 2 years

    I currently have this in this part of Inno script

    [Run]
    Filename: {app}\bin\vcredist_x86.exe; Parameters: "/q:a /c:""VCREDI~3.EXE /q:a /c:""""msiexec /i vcredist.msi /qn"""" """; WorkingDir: {app}\bin; StatusMsg: Installing Visual Studio 2010 C++ CRT Libraries...
    

    It will run vcredist installer during app installation. But the problem with this is that if the user has it already installed it throws things like

    • Repair/Remove
    • Already newer version detected

    Is there any way to avoid this and only run this installer if needed? What should i add to Inno script?

    EDIT:

    With the help of @John links i made it witht he following function added

    I also used this site for refference to get visual studio 2010 crt++ product code and used Uninstall folder in registry to detect if its installed.

    function InitializeSetup(): Boolean;
    var
      ErrorCode: Integer;
      RedistInstalled : Boolean;
      Result1 : Boolean;
    begin
      RedistInstalled := RegKeyExists(HKLM,'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{196BB40D-1578-3D01-B289-BEFC77A11A1E}');
      if RedistInstalled then
      begin
        Result := true;
      end else
      begin
        RedistInstalled := RegKeyExists(HKLM,'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{196BB40D-1578-3D01-B289-BEFC77A11A1E}');
        if RedistInstalled then
        begin
          Result := true;
        end else
        begin
          Result1 := MsgBox('This setup requires Microsoft Visual C++ 2010 Redistributable Package (x86). Please install Visual C++ 2010 Redistributable Package (x86) and run this setup again.  '#13#10' '#13#10'Do you want to download Microsoft Visual C++ 2010 Redistributable Package (x86) now?',
            mbConfirmation, MB_YESNO) = idYes;
          if Result1 =false then
          begin
            Result:=false;
          end else
          begin
            Result:=false;
            ShellExec('open',
              'http://download.microsoft.com/download/5/B/C/5BC5DBB3-652D-4DCE-B14A-475AB85EEF6E/vcredist_x86.exe',
              '','',SW_SHOWNORMAL,ewNoWait,ErrorCode);
          end;
        end;
      end;
    end;
    

    It would still be nice if however installer would continue after downloading/installing or that i could somehow adapt my previous code that runs included(with setup) installer:

     [Run]
        Filename: {app}\bin\vcredist_x86.exe; Parameters: "/q:a /c:""VCREDI~3.EXE /q:a /c:""""msiexec /i vcredist.msi /qn"""" """; WorkingDir: {app}\bin; StatusMsg: Installing Visual Studio 2010 C++ CRT Libraries...
    

    but this is still good enough.

  • Miral
    Miral almost 12 years
    .NET is an entirely different thing from the CRT.
  • TLama
    TLama almost 12 years
    For those who wants to install the framework at installation time (after you go through the whole wizard and run the installation process), don't run the framework setup in InitializeSetup event, it would start to install the framework immediately when you run your setup wizard, what is wrong for user's experience. Use the Check conditional parameter in your [Run] section, like this way.
  • Dielo
    Dielo about 11 years
    The question was how to check for visual c... why the answer is about framework :S ?