tags:

views:

67

answers:

2

Hey guys. Any one have an idea of how to install .NET framework before the setup in INNO Script?

A: 

You can use a [Run] section to launch an executable. The redistributable .NET installer is an executable. For example, you can download the installer for .NET 2.0 here.

See also the Inno Setup documentation.

Wim Coenen
By the use of [run] section it run always but i don't want to run every time i just want to run when there is no .net frame work in the machine.
Krish
A: 

Hi, here is a possible solution, inside InitializeWizard() method you check on the registry for the specific version of the .net framework that you need, if it is not present, then you can include, as a part of your inno installer, the framework web installer, and you can execute it, and wait for it to conclude, and depending on whether it was successfully installed or not, you may choose to continue or to abort the install.

Also, have in mind that some .net framework installers may require a reboot after installation, in that case, you also may want to include a key on the registry, under the run-once or run keys, so your installer gets called after the reboot (in case the user has chosen to reboot immediately after install).

Here is an example of this:

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 would still need to find a way to get the path of the executing installer, if you want to set the key on the registry, but aside of that, I think this code can help you with your question.

Vic