1
votes

I'm developing an application in C#. I'm trying to create the installation pack using Inno Setup, but I need to check if the user has the .NET framework installed. I did this, but here goes the problem: if the user doesn't want to install the .NET 4, the program needs to cancel the installation. How can I do this?

[Run]
Filename: "{app}\dotNetFx40_Full_x86_x64.exe"; Check: FrameworkIsNotInstalled
Filename: "{app}\sis_visu_ipccV2.0.exe"; Description: "{cm:LaunchProgram,SisIPCCAR4}"; Flags: nowait postinstall skipifsilent

[Code]
function FrameworkIsNotInstalled: Boolean;
begin
  if MsgBox('Foi detectado que seu computador não possui o .NET Framework 4.0. Para que o aplicativo execute normalmente é necessário tê-lo instalado. Deseja instalar? ', mbConfirmation, MB_YESNO or MB_DEFBUTTON2) = IDYES then
   begin
     Result := not RegKeyExists(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\.NETFramework\policy\v4.0');
    end
    else begin
      Abort;
    end; 
end;
1
In that case I would change the order and perform the .NET Check + display the message right after setup initializes. There is no much sense of installing all files and then... canceling the setup at the very end.RobeN
How can I display the message right after setup initializes? Sorry, but I started using Inno these days. My code doesn't work!user3628552
You can implement or call your Check function in function InitializeSetup(): Boolean; and then pass the result (e.g. as Q) from Message Box to the Result of this function. E.g. if Q = IDYES then Result := True); what will continue the Setup.RobeN
Sorry man, i didn't understand. Where is the function InitializeSetup? And I didn't understand the (e.g as Q) ...user3628552
Please find the example on my Pastebin: pastebin.com/8Tf1hhfERobeN

1 Answers

1
votes

I would check and ask for the permission of .NET installation at the very beginning.

If user will choose NOT to install .NET, the installation process will be terminated.

If user will AGREE to install .NET, the installation process will run normally, and the .NET will be installed at the end of installation (via RUN section).


You may move it from RUN section to BeforeInstall or choose other solution, but that would require to write additional piece of code.


Example:

[Run]
Filename: "{app}\dotNetFx40_Full_x86_x64.exe"; WorkingDir: "{app}"; 
 Parameters: "/passive /norestart"; Flags: waituntilterminated skipifdoesntexist; 
 StatusMsg: "{cm:dotNetInstallation}"; Check: not dotNetInstalled
Filename: "{app}\sis_visu_ipccV2.0.exe"; Description: "{cm:LaunchProgram,SisIPCCAR4}"; 
 Flags: nowait postinstall skipifsilent

[CustomMessages]
dotNETnotpresent=Foi detectado que seu computador não possui o .NET Framework 4.0. Para que o aplicativo execute normalmente é necessário tê-lo instalado. %n%nDeseja instalar? 
dotNetInstallation=Installation of .NET Framework 4.0 in progress...

[Code]
var
    dotNetBool: Boolean;

function InitializeSetup(): Boolean;
var
  Q: Integer;
begin
    Result := False;
    dotNetBool := False;
    if not RegKeyExists(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\.NETFramework\policy\v4.0') then begin
    //Registry entry was not found, quesion will appear
        Q := MsgBox(ExpandConstant('{cm:dotNETnotpresent}'), mbInformation, MB_YESNO);      
        if Q = IDYES then begin
        //If the asnwer is YES, Setup will initialize 
        //If the answer is NO, Setup will terminate
            Result := True;
        end;
    end
    else begin
    //Registry entry was found, Setup will initialize
        dotNetBool := True;
        Result := True;
    end;
end;

function dotNetInstalled: Boolean;
begin
  Result := dotNetBool;
end;