Click here to Skip to main content
14,601,203 members

InnoSetup with .NET installer x86/x64 sample

Rate this:
5.00 (19 votes)
Please Sign up or sign in to vote.
5.00 (19 votes)
10 Dec 2012CPOL
Prepare an installer that verifies the system's architecture and that .NET is installed.


The purpose of this intallation script sample is to launch an installer that checks for the .NET version currently installed on the system and install one only if required. The setup will include the web installer provided by Microsoft inside its package. 

The installer will also install some libraries depending on the architecture from where it runs.


For our purposes, we need the InnoSetup compiler and the .NET Framework web installer file downloadable from the Microsoft download site.

Using the code

.NET Installer section

First of all, it's always a good practice to define the working folder where we put the files used by the installer;

Something like this:

#define MyDistFolder "E:\dist\MyApp" 

In the [Code] section, we now define the functions that check for the .NET version installed.

This code is directly taken from Jordan Russell's site.

function IsDotNetDetected(version: string; service: cardinal): boolean;
// Indicates whether the specified version and service pack of the .NET Framework is installed.
// version -- Specify one of these strings for the required .NET Framework version:
//    'v1.1.4322'     .NET Framework 1.1
//    'v2.0.50727'    .NET Framework 2.0
//    'v3.0'          .NET Framework 3.0
//    'v3.5'          .NET Framework 3.5
//    'v4\Client'     .NET Framework 4.0 Client Profile
//    'v4\Full'       .NET Framework 4.0 Full Installation
//    'v4.5'          .NET Framework 4.5
// service -- Specify any non-negative integer for the required service pack level:
//    0               No service packs required
//    1, 2, etc.      Service pack 1, 2, etc. required
    key: string;
    install, release, serviceCount: cardinal;
    check45, success: boolean;
var reqNetVer : string;
    // .NET 4.5 installs as update to .NET 4.0 Full
    if version = 'v4.5' then begin
        version := 'v4\Full';
        check45 := true;
    end else
        check45 := false;

    // installation key group for all .NET versions
    key := 'SOFTWARE\Microsoft\NET Framework Setup\NDP\' + version;

    // .NET 3.0 uses value InstallSuccess in subkey Setup
    if Pos('v3.0', version) = 1 then begin
        success := RegQueryDWordValue(HKLM, key + '\Setup', 'InstallSuccess', install);
    end else begin
        success := RegQueryDWordValue(HKLM, key, 'Install', install);

    // .NET 4.0/4.5 uses value Servicing instead of SP
    if Pos('v4', version) = 1 then begin
        success := success and RegQueryDWordValue(HKLM, key, 'Servicing', serviceCount);
    end else begin
        success := success and RegQueryDWordValue(HKLM, key, 'SP', serviceCount);

    // .NET 4.5 uses additional value Release
    if check45 then begin
        success := success and RegQueryDWordValue(HKLM, key, 'Release', release);
        success := success and (release >= 378389);

    result := success and (install = 1) and (serviceCount >= service);

This is a global function that verifies if the .NET Framework version passed as an argument is properly installed. 

Now we should write a simple function that is called by the installer in runtime, to verify if the required .NET version is installed. We'll use 4.0 as an example.

function IsRequiredDotNetDetected(): Boolean;  
    result := IsDotNetDetected('v4\Full', 0);

If we want, we can also release a message during the setup process:

function InitializeSetup(): Boolean;
    if not IsDotNetDetected('v4\Full', 0) then begin
        MsgBox('{#MyAppName} requires Microsoft .NET Framework 4.0 Client Profile.'#13#13
          'The installer will attempt to install it', mbInformation, MB_OK);        
    result := true;

The code section is complete, now we can focus on the [Files] section.

Source: "{#MyDistFolder}\dotNetFx40_Full_setup.exe"; DestDir: {tmp}; Flags: deleteafterinstall; Check: not IsRequiredDotNetDetected

The setup will copy the .NET installer file (which is a smart file of about 850 KB), only if is not already present in the system, to the system temp directory. Once the install finishes, the file will be deleted.

Now that the net web installer is copied, we need to run it if required.

In the [Run] section, write this:

Filename: {tmp}\dotNetFx40_Full_setup.exe; Parameters: "/q:a /c:""install /l 
  /q"""; Check: not IsRequiredDotNetDetected; StatusMsg: Microsoft Framework 4.0 is beïng installed. Please wait... 

And that's all.

x86/x64 options

This sample shows how the installer behaves according to the system architecture.

It will install the native libraries required by the system in order to make a more smart installation.

In the [Setup] section, define this directive:


These two rows will install a lib folder according to the system:

Source: "{#MyDistFolder}\lib\x64\*"; DestDir: "{app}\lib\x64"; Check: Is64BitInstallMode; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "{#MyDistFolder}\lib\x86\*"; DestDir: "{app}\lib\x86"; Check: not Is64BitInstallMode; Flags: ignoreversion recursesubdirs createallsubdirs 

Points of Interest

With just a few lines of script we are capable of making a smart setup installer, and even more a smart installation, saving space for native architecture libraries.



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Fabrizio Stellato
Software Developer (Senior)
Italy Italy
Creator of:
Impulse Media Player
Audio Pitch & Shift
Ultimate Music Tagger
Modern Log Viewer
Pitch Tuner
Modern Audio Tagger
Win Log Inspector
Win Log Analyzer

Comments and Discussions

GeneralIt uses the correct regkey for the version-check :) Pin
Michael900017-May-14 4:22
MemberMichael900017-May-14 4:22 
QuestionInstallation Types Pin
Yonathan111110-May-14 8:24
professionalYonathan111110-May-14 8:24 
AnswerRe: Installation Types Pin
Michael900017-May-14 3:59
MemberMichael900017-May-14 3:59 
GeneralRe: Installation Types Pin
Yonathan111117-May-14 6:00
professionalYonathan111117-May-14 6:00 
QuestionVery useful Pin
vjedlicka4-Dec-13 22:29
Membervjedlicka4-Dec-13 22:29 
GeneralMy vote of 5 Pin
İbrahim Ates28-Aug-13 19:18
Memberİbrahim Ates28-Aug-13 19:18 
GeneralMy vote of 5 Pin
Gurdeep Singh Toor20-Aug-13 1:21
MemberGurdeep Singh Toor20-Aug-13 1:21 
GeneralMy vote of 5 Pin
Nik Todorov17-Apr-13 10:09
MemberNik Todorov17-Apr-13 10:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 10 Dec 2012

Tagged as


29 bookmarked