.NET Framework as a pre-requisite for installation with Inno-Setup
Asked Answered
R

1

7

I have an application I have to check if .NET FW 3.5 has already installed. If already installed, I want to open a messagebox that asks the user to download it from Microsoft website and stop the installation.

I found the following code. Can you tell me please:

a) Where should I call this function from? b) Should I check if .NET FW 3.5 or higher version is already installed? e.g. If FW 4.0 installed - is that necessary to install 3.5?

Thank you

function IsDotNET35Detected(): Boolean;
var
  ErrorCode: Integer;
  netFrameWorkInstalled : Boolean;
  isInstalled: Cardinal;
begin
  result := true;

  // Check for the .Net 3.5 framework
  isInstalled := 0;
  netFrameworkInstalled := RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5', 'Install', isInstalled);
  if ((netFrameworkInstalled)  and (isInstalled <> 1)) then netFrameworkInstalled := false;

  if netFrameworkInstalled = false then
  begin
    if (MsgBox(ExpandConstant('{cm:dotnetmissing}'), mbConfirmation, MB_YESNO) = idYes) then
    begin
      ShellExec('open',
      'http://www.microsoft.com/downloads/details.aspx?FamilyID=333325fd-ae52-4e35-b531-508d977d32a6&DisplayLang=en',
      '','',SW_SHOWNORMAL,ewNoWait,ErrorCode);
    end;
    result := false;
  end;

end;
Reverso answered 19/10, 2012 at 14:38 Comment(0)
S
7

If you want to perform your check when the installation starts but before the wizard form is shown, use the InitializeSetup event handler for it. When you return False to that handler, the setup will abort, when True, setup will start. Here's a little bit optimized script you've posted:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[CustomMessages]
DotNetMissing=.NET Framework 3.5 is missing. Do you want to download it ? Setup will now exit!

[Code]
function IsDotNET35Detected: Boolean;
var
  ErrorCode: Integer;
  InstallValue: Cardinal;  
begin
  Result := True;
  if not RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5', 
    'Install', InstallValue) or (InstallValue <> 1) then
  begin
    Result := False;
    if MsgBox(ExpandConstant('{cm:DotNetMissing}'), mbConfirmation, MB_YESNO) = IDYES then
      ShellExec('', 'http://www.microsoft.com/downloads/details.aspx?FamilyID=333325fd-ae52-4e35-b531-508d977d32a6&DisplayLang=en',
        '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
  end;
end;

function InitializeSetup: Boolean;
begin
  Result := IsDotNET35Detected;
end;
Salve answered 19/10, 2012 at 15:0 Comment(8)
I know I've answered none of your questions. I'll come back with an update soon... But I have to go now...Salve
Thank you. I'll try it. What about higher ( > 3.5) versions? Is that true to say that if FW 4.0 is installed, it covers the needs for 3.5?Reverso
It depends on your application as it's said in this article. But no one clearly said, that if you install e.g. .NET 4.5 on a computer without .NET Framework 3.5 installed, that you'll be able to apply this kind of a detection.Salve
How it sounds please? I think I'll check for all the three: 3.5, 4.0 and 4.5; If none are installed - I stop the installation and ask the user to download v3.5; If 3.5 was not installed but 4.0 or 4.5 did - I let the user to decide whether to stop and download 3.5 or try to install and launch my application anywayReverso
That sounds fine! As my colleague (a long time .NET developer) confirmed, the applications written in .NET 3.5 should run on newer frameworks without problems (except few compatibility differences) but as even MS itself states "for applications that target versions 1.1, 2.0, and 3.5, you can install the appropriate version of the .NET Framework on the target machine to run the application in its best environment" so I think it's a good way to ask user if he/she wants to download and install .NET 3.5 since it's a recommended part for successful running of your application.Salve
If I'd have Ultimate version of my Windows 7, I'd try to simulate all of this in the XP mode (or some other virtual machine, if I'd have some). Plain Windows XP without SP had just .NET Framework 2.0 preinstalled if I remember that right, so installing e.g. version 4.5 would show, what's in the registry and what's really installed by the 4.5 version. But I don't have any of this :-(Salve
I have test results from Windows XP Mode. I have installed on a fresh installation of Windows XP Mode system .NET Framework 4.0 (since 4.5 is not supported on Windows XP) and the registry key for .NET 3.5 were not present in the system after .NET 4.0 installation.Salve
also in XP windows installer 3.1 should be installed before the .net framework 3.5 as it is a prerequisite for it.Damara

© 2022 - 2024 — McMap. All rights reserved.