Reputation: 13
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;
Upvotes: 1
Views: 601
Reputation: 5456
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;
Upvotes: 1