Install .Net infrastructure with my Inno installation application

Does anyone have an idea to install the .NET framework before installing in INNO Script?

+3
source share
3 answers

here is the complete solution for all versions of .Net and additional software: CodeProject

ps I know this question is quite old, but this project should be part of the answers ...

[EDIT by @jitbit]: the latest source of CodeProject article can be found here: https://github.com/stfx/innodependencyinstaller

+3
source

[Run] . .NET . , .NET 2.0 .

. Inno.

+2

, InitializeWizard() .net-, , , -, - , , , , ​​ , .

In addition, keep in mind that some installers of the .NET Framework may need to reboot after installation, in which case you can also include the key in the registry under the startup or startup keys so that your installer receives after reboot (in case the user decided to restart immediately after installation).

Here is an example:

function CheckIfFrameworkNeeded(): Boolean;
var
  VersionFrameWork: Cardinal;
  FrameWorkNeeded: Boolean;
begin
  FrameWorkNeeded := true;
   //**********************************************************************
   //  Check Fot Framewok 3.5.
   //**********************************************************************
    if (RegQueryDWordValue(HKLM, 'Software\Microsoft\NET Framework Setup\NDP\v3.5', 'Install', VersionFrameWork)) then
    begin
      if (VersionFrameWork = 1) then
          FrameWorkNeeded := false
    end;

   Result := FrameWorkNeeded;
end;

function Install_NETFramework() : Integer;
var
  hWnd: Integer;
  ResultCode: Integer;
  dotnetRedistPath: string;
  outVar : string;
begin

  dotnetRedistPath:= ExpandConstant('{tmp}\dotnetfx35setup.exe');

  //*********************************************************************************
  // Run the install file for .NET Framework 3.5. This is usually dotnetfx35setup.exe from MS
  //***********************************************************************************

  if Exec(ExpandConstant(dotnetRedistPath), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
  begin
     // ResultCode contains the exit code
     case ResultCode of
     // 1641 The requested operation completed successfully. The system will be restarted so the changes can take effect.
     // 3010 The requested operation is successful. Changes will not be effective until the system is rebooted.
     1641:
     begin
        Result := 1;
     end
     3010, 0:
     begin
        Result := 0;
     end else // -> case default
     begin
        Result := -1;
     end
  end;
  end else
  begin
     //handle failure if necessary; ResultCode contains the error code
     Result := -1;
  end;
end;

procedure InitializeWizard();
var
   frameworkNeeded: Boolean;
   installerPath: String;
   res: integer;
begin
  frameworkNeeded := CheckIfFrameworkNeeded();
  if (frameworkNeeded = true)then
  begin
    if MsgBox('This setup requires the .NET Framework 3.5.'#13 + 'The .NET Framework can be obtained from the web.'#13 + 'Would you like to do this now?', mbConfirmation, MB_YESNO) = IDYES then
    begin
      // register in the registry the path to your current installer, so it gets called after a reboot
      RegWriteStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Run', 'MyAppKey', installerPath); // installerPath is the path of your installer
      res := Install_NETFramework();
      case res of
        1:  // a restart is going to be executed right away so we abort to avoid the reboot from happening
        begin
          Abort;
        end
        0: // a restart is going to be executed later
        begin
          //Delete the key we added before since we don't need it cause we are installing now
          RegDeleteValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Run', 'MyAppKey');
          // continue with your installation here
        end
        -1: // an error happened
        begin
          Abort;
        end
      end;
      end else
       begin
        //The user has chosen not to install the framework
        MsgBox('The application can not be installed unless the framework 3.5 be installed first.', mbError, MB_OK);
        Abort;
       end;
      end else
     begin
      // the framework is present so continue with your installation here
     end;
end;

I think you still need to find a way to get the path to the executing installer if you want to install the key in the registry, but in addition, I think this code can help you with your question.

0
source

Source: https://habr.com/ru/post/1762541/


All Articles