Friday, May 18, 2012 Register  Login

This site uses DNS Made Easy. Use it for reliable and professional DNS services.

RSS Feeds
Categories
  
Blog Archives
  
Blog

InnoSetup - Detecting and Downloading .NET 2.0

Here's the script in a zip file:

DotNet2Install.zip

 

You will need to get Download DLL from http://www.istool.org/default.aspx/isx/isxdl, then change the path to isxdl.dll under the [Files] section.

[UPDATE: October 27, 2008]
Apparently the binary for the Download DLL is not being hosted separately anymore. It is now part of ISTool. Just download ISTool, install it, and look in the install directory for isxdl.dll. It is there with documentation on  how to use with programming languages. I already included all that is needed to work with this script.

Here's the script's code for those that don't want to bother downloading the zip file:

[Setup]
AppName=.NET 2.0 Test Install
AppVerName=Test
AppVersion=Test Script
AppPublisher=SystemWidgets
MinVersion=0,5.01.2600
DefaultDirName={pf}\SystemWidgets

[Files]
Source: ..\..\..\..\..\..\Dev\Tools\Download DLL\isxdl.dll; DestDir: {tmp}; Flags: deleteafterinstall

[Code]
var
    dotnetRedistPath: string;
    downloadNeeded: boolean;
    dotNetNeeded: boolean;
    memoDependenciesNeeded: string;
    Version: TWindowsVersion;

procedure isxdl_AddFile(URL, Filename: PChar);
external 'isxdl_AddFile@files:isxdl.dll stdcall';
function isxdl_DownloadFiles(hWnd: Integer): Integer;
external 'isxdl_DownloadFiles@files:isxdl.dll stdcall';
function isxdl_SetOption(Option, Value: PChar): Integer;
external 'isxdl_SetOption@files:isxdl.dll stdcall';

const
    dotnetRedistURL = 'http://download.microsoft.com/download/5/6/7/567758a3-759e-473e-bf8f-52154438565a/dotnetfx.exe';

//*********************************************************************************
// This is where all starts.
//*********************************************************************************
function InitializeSetup(): Boolean;

begin

    Result := true;
    dotNetNeeded := false;
    GetWindowsVersionEx(Version);

    //*********************************************************************************
    // Check for the existance of .NET 2.0
    //*********************************************************************************
    if (not RegKeyExists(HKLM, 'Software\Microsoft\.NETFramework\policy\v2.0')) then
        begin
            dotNetNeeded := true;

            if (not IsAdminLoggedOn()) then
                begin
                    MsgBox('This program needs the Microsoft .NET Framework 2.0 to be installed by an Administrator', mbInformation, MB_OK);
                    Result := false;
                end
            else
                begin
                    memoDependenciesNeeded := memoDependenciesNeeded + '      .NET Framework 2.0' #13;
                    dotnetRedistPath := ExpandConstant('{src}\dotnetfx.exe');
                    if not FileExists(dotnetRedistPath) then
                        begin
                            dotnetRedistPath := ExpandConstant('{tmp}\dotnetfx.exe');
                            if not FileExists(dotnetRedistPath) then
                                begin
                                    isxdl_AddFile(dotnetRedistURL, dotnetRedistPath);
                                    downloadNeeded := true;
                                end
                        end

                    SetIniString('install', 'dotnetRedist', dotnetRedistPath, ExpandConstant('{tmp}\dep.ini'));
                end
        end;

end;

function NextButtonClick(CurPage: Integer): Boolean;

var
  hWnd: Integer;
  ResultCode: Integer;
  ResultXP: boolean;
  Result2003: boolean;

begin

  Result := true;
  ResultXP := true;
  Result2003 := true;

  //*********************************************************************************
  // Only run this at the "Ready To Install" wizard page.
  //*********************************************************************************
  if CurPage = wpReady then
    begin

        hWnd := StrToInt(ExpandConstant('{wizardhwnd}'));

        // don't try to init isxdl if it's not needed because it will error on < ie 3

        //*********************************************************************************
        // Download the .NET 2.0 redistribution file.
        //*********************************************************************************
        if downloadNeeded and (dotNetNeeded = true) then
            begin
                isxdl_SetOption('label', 'Downloading Microsoft .NET Framework 2.0');
                isxdl_SetOption('description', 'This program needs to install the Microsoft .NET Framework 2.0. Please wait while Setup is downloading extra files to your computer.');
                if isxdl_DownloadFiles(hWnd) = 0 then Result := false;
            end;

        //*********************************************************************************
        // Run the install file for .NET Framework 2.0. This is usually dotnetfx.exe
        //*********************************************************************************
            if (dotNetNeeded = true) then
            begin

                if Exec(ExpandConstant(dotnetRedistPath), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
                    begin

                        // handle success if necessary; ResultCode contains the exit code
                        if not (ResultCode = 0) then
                            begin

                                Result := false;

                            end
                    end
                    else
                        begin

                            // handle failure if necessary; ResultCode contains the error code
                            Result := false;

                        end
            end;

    end;

end;

//*********************************************************************************
// Updates the memo box shown right before the install actuall starts.
//*********************************************************************************
function UpdateReadyMemo(Space, NewLine, MemoUserInfoInfo, MemoDirInfo, MemoTypeInfo, MemoComponentsInfo, MemoGroupInfo, MemoTasksInfo: String): String;
var
  s: string;

begin

  if memoDependenciesNeeded <> '' then s := s + 'Dependencies that will be automatically downloaded And installed:' + NewLine + memoDependenciesNeeded + NewLine;
  s := s + MemoDirInfo + NewLine + NewLine;

  Result := s

end;

posted @ Thursday, August 02, 2007 5:25 PM by Hector Sosa, Jr

Posted in: Inno Setup

Actions:Tweet This Share on Facebook Share on LinkedIn Emakl Permalink del.icio.us

Previous Page | Next Page

COMMENTS

Very kind of you, thank you!

posted @ Friday, August 03, 2007 2:47 AM by Richard


Thank you very much for covering the topic of .NET 2.0 pre-install.

Please forgive my naive question but what is the language used for the script that you are presenting? I am usually using WIX to create the installation package for my .NET applications. Is you are approach "compatible" with WIX ?

Thanks in advance,
Joannès

posted @ Tuesday, August 07, 2007 3:02 PM by Joannes


This script is for the freely available InnoSetup, an installation software. The language in the [Code] section is Pascal. Unfortunately, this is not compatible with WiX. WiX is a whole different installation system.

You can get InnoSetup here:
http://www.jrsoftware.org/isinfo.php

posted @ Tuesday, August 07, 2007 7:12 PM by Hector Sosa, Jr


hi i found the link in dot net forums..... thanx for the code it helped me a lot.... i am new to innosetup and can u tell me how to implement maintainence screen that is repair,modify kinda thing using innosetup....

Regards,
Marc

posted @ Tuesday, January 01, 2008 11:12 PM by Marc


There's a 3rd party extension that supposedly does this.

http://www.han-soft.com/uninshs.php

I haven't tried myself.

posted @ Wednesday, January 02, 2008 9:48 AM by Hector Sosa, Jr


hey i tweaked your code and added still more features to check previous installed version and to automatically uninstall it and to check whether whether application is already running and made script available for download in my blog

http://www.ceveni.com/2008/03/check-dotnet-framework-using-innosetup.html

posted @ Tuesday, January 20, 2009 1:00 PM by Ceveni


Thank you that is really helpful.
The good thing is that you are not like the other they just write part of there code then say here is the solution.
your code work very well and it's really good work from you

posted @ Saturday, January 07, 2012 4:46 AM by kilany


Name (required)

Email (required)

Website

CAPTCHA image
Enter the code shown above:

Terms Of Use | Privacy Statement | SystemWidgets
Copyright 2002-2012 by SystemWidgets
Google Analytics Alternative