9

I'm new to InnoSetup as I am experimenting with various installers.

I created my first script using Inno Script Studio and the built in wizards. So far so good. Now I want to get it to detect if .Net 4.5 is installed and if it isn't then install it. So, I looked all over the web and on here and I came across this solution, however when I copy and paste the code into my script I get the following error when compiling.

Compiling [Code] section
Compiler Error!
Line 54: Column 10: Invalid prototype for 'IsDotNetDetected'

and Line 54 in my script is this

function IsDotNetDetected(version: string; service: cardinal): boolean;

anyone know what the error means and why I am getting it?

Here's my full script:

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "AVO Log"
#define MyAppVersion "0.1.0.1"
#define MyAppPublisher "NA"
#define MyAppExeName "AVO Log.exe"

[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{9476587F-A670-4E17-B8EA-A6FABB345968}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}  
AppPublisher={#MyAppPublisher}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
AllowNoIcons=yes
OutputBaseFilename=setup
Compression=lzma
SolidCompression=yes

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1

[Files]
Source: "G:\Common\Gareths Apps\dotNetFx45_Full_x86_x64.exe"; DestDir: {tmp}; Flags: deleteafterinstall;
Source: "C:\Visual Studio 2010\Projects\AVO Log\AVO Log\bin\Release\AVO Log.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Visual Studio 2010\Projects\AVO Log\AVO Log\bin\Release\GalaSoft.MvvmLight.Extras.WPF45.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Visual Studio 2010\Projects\AVO Log\AVO Log\bin\Release\GalaSoft.MvvmLight.WPF45.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Visual Studio 2010\Projects\AVO Log\AVO Log\bin\Release\GalaSoft.MvvmLight.WPF45.xml"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Visual Studio 2010\Projects\AVO Log\AVO Log\bin\Release\Microsoft.Expression.Interactions.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Visual Studio 2010\Projects\AVO Log\AVO Log\bin\Release\Microsoft.Practices.ServiceLocation.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Visual Studio 2010\Projects\AVO Log\AVO Log\bin\Release\System.Windows.Interactivity.dll"; DestDir: "{app}"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon

[Run]
Filename: "{tmp}\dotNetFx45_Full_x86_x64.exe"; Check: IsDotNetDetected('v4.5',0)
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent

[Code]
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
var
key: string;
install, release, serviceCount: cardinal;
check45, success: boolean;
begin
// .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);
end;

// .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);
end;

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

result := success and (install = 1) and (serviceCount >= service);
end;
Deanna
  • 23,876
  • 7
  • 71
  • 156
Gaz83
  • 2,293
  • 4
  • 32
  • 57

2 Answers2

19

My psychic powers tell me that you're trying to use this function as a check: parameter. As functions used with check: parameters must have a specific prototype, the compiler is failing.

Try using this stub function:

function CheckIsDotNetDetected(): boolean;
begin
    result := IsDotNetDetected('v4\Client', 0);
end;
Deanna
  • 23,876
  • 7
  • 71
  • 156
  • @Gaz83 You don't explcitly mention that you're using `check:` parameters. That is the one thing that you added over the original article that caused the problem. – Deanna Mar 19 '13 at 12:57
  • @Deanna Sorry if this sounds dumb but what do you mean? In the original article the author used a `check:` in a `InitializeSetup()` function. Although I am not using that function I am still running a `check:`. See the first line under `[Run]`... unless I'm totally doing this wrong lol – Gaz83 Mar 19 '13 at 13:18
  • The author of that article used that function as a check in code, not as the [`Check`](http://jrsoftware.org/ishelp/topic_scriptcheck.htm#Check) parameter of a section entry. – TLama Mar 19 '13 at 14:07
  • Ok, so what do I need to do to my script to get it to work? I basically want to check if .Net 4.5 is installed and if its not then install it with dotNetFx45_Full_x86_x64.exe that I have included – Gaz83 Mar 19 '13 at 14:15
  • I think I may have figured it out, just doing some testing – Gaz83 Mar 19 '13 at 14:30
  • @Gaz83 have you read the [answer](http://stackoverflow.com/a/15498900/588306) you're actually replying to? – Deanna Mar 19 '13 at 14:30
  • @Gaz83, yes, that article does a check, but not by using a `check:` parameter. – Deanna Mar 19 '13 at 14:32
  • Here is [`an example`](http://stackoverflow.com/a/12829386/960757). Although I'm still wondering about such complicated determination of installed version. – TLama Mar 19 '13 at 14:47
  • @Deanna as I mentioned in my post I am new to all this, my background is c# and I was confused on the term check: parameter. All I was thinking was "Yeah, I was performing a check and what's the problem?" but after reading the answer again and again and the comments I think I had a light bulb moment. :-) – Gaz83 Mar 19 '13 at 14:48
2

Example of check for .Net 4 for 32bit systems

function NET4032(): Boolean;
var
InstallCheck : Cardinal;
begin
  RegQueryDWordValue(HKLM32, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full', 
'Install', InstallCheck);
    if InstallCheck = $1 then
       Result := false
    else
       Result := true;
end;
RobeN
  • 5,346
  • 1
  • 33
  • 50
  • @TLama - you could just correct my answer :D. I'm Million Miles Away from you when talking about skills and knowledge... – RobeN Mar 19 '13 at 13:20