Disclaimer: Some
of
this s
-
c
-
r
-
i
-
p
-
t is adapted from an example I found on another website, I have been unable
to
retrace the original,
if
you recognise some
of
this work as your own please contact me
and
I would be happy
to
credit you.
There are a few key parts to creating a silent install controlled by Inno to install .Net Framework and SQL server.
1 ).
First you need to create a .ini file containing the parameters to be passed to the SQL Server installer. For most basic or simple installations you will need only a few of lines inside this file .
[Options]
ADDLOCAL = SQL_Engine
INSTANCENAME = YOURINSTANCENAME
(setup.ini)
The firstline [Options] needs to be there it doesn’t really do anything.
ADDLOCAL = SQL_Engine - this tells the installed to install a new database engine, you could replace this with ADDLOCAL = All - this would install all possible features of the SQL Server Express. However this is in most cases unlikely to be neccesary.
INSTANCENAME = YOURINSTANCENAME - replace ‘YOURINSTANCENAME’ with any name you like, this is to distinguish your database engine from those installed by other programs.
2 ).
The Script notice all the usual InnoSetup s - c - r - i - p - t and then a section at the end [code] anything after this is in the PASCAL programming language. If you have never used pascal it is almost a cross between C and BASIC / VB.
If you are used to programming in C when you see “ then begin ” read it as ‘ { ’ and when you see “end” read it as ‘ } ’, you will then find it makes a lot more sense, all that is left is a few syntatical differences.
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName “AppName”
#define MyAppVerName “AppName version”
#define MyAppPublisher “Company Name”
#define MyAppURL “CompanyWebsite”
#define MyAppExeName “Appname.exe“
[Setup]
AppName = { #MyAppName }
AppVerName = { #MyAppVerName }
AppPublisher = { #MyAppPublisher }
AppPublisherURL = { #MyAppURL }
AppSupportURL = { #MyAppURL }
AppUpdatesURL = { #MyAppURL }
DefaultDirName = { pf } \ { #MyAppName }
DefaultGroupName = { #MyAppName }
OutputDir = C:\SetupBuild\Output
OutputBaseFilename = Setup
Compression = lzma
SolidCompression = yes
[Languages]
Name: english; MessagesFile: compiler:Default.isl
[Tasks]
Name: desktopicon; Des - c - r - i - p - tion: { cm:CreateDesktopIcon } ; GroupDes - c - r - i - p - tion: { cm:AdditionalIcons } ; Flags: unchecked
[Files]
Source: C:\Program Files\ISTool\isxdl.dll; Flags: dontcopy ;(this DLL is required to compile)
Source: C:\filenames.exe; DestDir: { app } ; Flags: ignoreversion
;Add the rest of you programs files above.
[Icons]
Name: { group } \ { #MyAppName } ; Filename: { app } \ { #MyAppExeName }
Name: { commondesktop } \ { #MyAppName } ; Filename: { app } \ { #MyAppExeName } ; Tasks: desktopicon
Name: { group } \ { cm:UninstallProgram, {#MyAppName } }; Filename: { uninstallexe }
[Run]
Filename: { app } \ { #MyAppExeName } ; Des - c - r - i - p - tion: { cm:LaunchProgram,{#MyAppName } }; Flags: nowait postinstall skipifsilent
[Code]
var
dotnetRedistPath: string;
sqlserverPath: string;
sqlNeeded: boolean;
sqlInstance: boolean;
downloadNeeded: boolean;
dotNetNeeded: boolean;
memoDependenciesNeeded: string;
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 / 6 / 0 / f / 60fc5854 - 3cb8 - 4892 - b6db - bd4f42510f28 / dotnetfx35.exe’;
// this url was correct at time of publication for .net 3.5 you may need to change this in future.
// local system for testing…
// dotnetRedistURL = ‘http: // 192.168 . 1.1 / dotnetfx35.exe’;
function InitializeSetup(): Boolean;
begin
Result : = true;
dotNetNeeded : = false;
sqlNeeded : = false;
sqlInstance: = false;
// Check for required netfx installation
if ( not RegKeyExists(HKLM, ‘Software\Microsoft\.NETFramework\AssemblyFolders\v3. 5 ′)) then begin
dotNetNeeded : = true;
if ( not IsAdminLoggedOn()) then begin
MsgBox(’GasSoft needs the Microsoft .NET Framework to be installed by an Administrator’, mbInformation, MB_OK);
Result : = false;
end else begin
memoDependenciesNeeded : = memoDependenciesNeeded + ‘ .NET Framework’ # 13 ;
dotnetRedistPath : = ExpandConstant(’ { src } \dotnetfx35.exe’);
if not FileExists(dotnetRedistPath) then begin
dotnetRedistPath : = ExpandConstant(’ { tmp } \dotnetfx35.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 ;
if ( not RegKeyExists(HKLM, ‘SOFTWARE\Microsoft\Microsoft SQL Server\ 90 \Tools’)) then begin
sqlNeeded : = true;
if ( not IsAdminLoggedOn()) then begin
MsgBox(’GasSoft needs Microsoft SQL Server to be installed by an administrator’, mbInformation, MB_OK);
Result : = false;
end else begin
memoDependenciesNeeded : = memoDependenciesNeeded + ‘ SQL Server Express 2005 ′ # 13 ;
sqlserverPath : = ExpandConstant(’ { src } \SQLEXPR32.EXE’);
end ;
end else begin
if ( not RegKeyExists(HKLM, ‘SOFTWARE\Microsoft\Microsoft SQL Server\YOURINSTACENAME‘)) then begin
sqlNeeded : = false;
sqlInstance : = true;
if ( not IsAdminLoggedOn()) then begin
MsgBox(’YOURAPPNAME needs Microsoft SQL Server to be installed by an administrator’, mbInformation, MB_OK);
Result : = false;
end else begin
memoDependenciesNeeded : = memoDependenciesNeeded + ‘ Add instance to SQL Server’ # 13 ;
sqlserverPath : = ExpandConstant(’ { src } \SQLEXPR32.EXE’);
end ;
end ;
end ;
end ;
function NextButtonClick(CurPage: Integer): Boolean;
var
hWnd: Integer;
ResultCode: Integer;
begin
Result : = true;
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
if downloadNeeded then begin
isxdl_SetOption(’ label ’, ‘Downloading Microsoft .NET Framework’);
isxdl_SetOption(’des - c - r - i - p - tion’, ‘YOURAPPNAME needs to install the Microsoft .NET Framework. Please wait while Setup is downloading extra files to your computer.’);
if isxdl_DownloadFiles(hWnd) = 0 then Result : = false;
end ;
if (Result = true) and (dotNetNeeded = true) then begin
if Exec(ExpandConstant(dotnetRedistPath), ‘ / qb’, ”, 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 ;
if (Result = true) and (sqlNeeded = true) and ( not sqlInstance = true) then begin
if Exec(ExpandConstant(sqlserverPath), ‘ / settings ‘ + ExpandConstant(’ { src } ’) + ’\setup.ini / qb’, ”, 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 ;
if (Result = true) and (sqlNeeded = false) and (sqlInstance = true) then begin
if Exec(ExpandConstant(sqlserverPath), ‘ / settings ‘ + ExpandConstant(’ { src } ’) + ’\setup.ini / qb’, ”, 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 ;
function UpdateReadyMemo(Space, NewLine, MemoUserInfoInfo, MemoDirInfo, MemoTypeInfo, MemoComponentsInfo, MemoGroupInfo, MemoTasksInfo: String): String;
var
s: string;
begin
if memoDependenciesNeeded <> ” then s : = s + ‘Dependencies to install:’ + NewLine + memoDependenciesNeeded + NewLine;
s : = s + MemoDirInfo + NewLine + NewLine;
Result : = s
end ;
You will find that some of the s - c - r - i - p - t (provided by unknown) cleverly checks to see if the .net files are included in the same directory “ { src } ” as the setup program , if not it runs a downloader program and downloads the required files. I have not adjusted the s - c - r - i - p - t to do this for SQL server as I did not deem this necessary, but if you struggle to make the changes yourself then feel free to contact me and I will try my best.
Now the s - c - r - i - p - t should compile and faultlessly install firstly the .net framework , and / or sql server express.
Highlighted in red are small sections you would need to change to customise this for your own use.
There are a few key parts to creating a silent install controlled by Inno to install .Net Framework and SQL server.
1 ).
First you need to create a .ini file containing the parameters to be passed to the SQL Server installer. For most basic or simple installations you will need only a few of lines inside this file .
[Options]
ADDLOCAL = SQL_Engine
INSTANCENAME = YOURINSTANCENAME
(setup.ini)
The firstline [Options] needs to be there it doesn’t really do anything.
ADDLOCAL = SQL_Engine - this tells the installed to install a new database engine, you could replace this with ADDLOCAL = All - this would install all possible features of the SQL Server Express. However this is in most cases unlikely to be neccesary.
INSTANCENAME = YOURINSTANCENAME - replace ‘YOURINSTANCENAME’ with any name you like, this is to distinguish your database engine from those installed by other programs.
2 ).
The Script notice all the usual InnoSetup s - c - r - i - p - t and then a section at the end [code] anything after this is in the PASCAL programming language. If you have never used pascal it is almost a cross between C and BASIC / VB.
If you are used to programming in C when you see “ then begin ” read it as ‘ { ’ and when you see “end” read it as ‘ } ’, you will then find it makes a lot more sense, all that is left is a few syntatical differences.
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName “AppName”
#define MyAppVerName “AppName version”
#define MyAppPublisher “Company Name”
#define MyAppURL “CompanyWebsite”
#define MyAppExeName “Appname.exe“
[Setup]
AppName = { #MyAppName }
AppVerName = { #MyAppVerName }
AppPublisher = { #MyAppPublisher }
AppPublisherURL = { #MyAppURL }
AppSupportURL = { #MyAppURL }
AppUpdatesURL = { #MyAppURL }
DefaultDirName = { pf } \ { #MyAppName }
DefaultGroupName = { #MyAppName }
OutputDir = C:\SetupBuild\Output
OutputBaseFilename = Setup
Compression = lzma
SolidCompression = yes
[Languages]
Name: english; MessagesFile: compiler:Default.isl
[Tasks]
Name: desktopicon; Des - c - r - i - p - tion: { cm:CreateDesktopIcon } ; GroupDes - c - r - i - p - tion: { cm:AdditionalIcons } ; Flags: unchecked
[Files]
Source: C:\Program Files\ISTool\isxdl.dll; Flags: dontcopy ;(this DLL is required to compile)
Source: C:\filenames.exe; DestDir: { app } ; Flags: ignoreversion
;Add the rest of you programs files above.
[Icons]
Name: { group } \ { #MyAppName } ; Filename: { app } \ { #MyAppExeName }
Name: { commondesktop } \ { #MyAppName } ; Filename: { app } \ { #MyAppExeName } ; Tasks: desktopicon
Name: { group } \ { cm:UninstallProgram, {#MyAppName } }; Filename: { uninstallexe }
[Run]
Filename: { app } \ { #MyAppExeName } ; Des - c - r - i - p - tion: { cm:LaunchProgram,{#MyAppName } }; Flags: nowait postinstall skipifsilent
[Code]
var
dotnetRedistPath: string;
sqlserverPath: string;
sqlNeeded: boolean;
sqlInstance: boolean;
downloadNeeded: boolean;
dotNetNeeded: boolean;
memoDependenciesNeeded: string;
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 / 6 / 0 / f / 60fc5854 - 3cb8 - 4892 - b6db - bd4f42510f28 / dotnetfx35.exe’;
// this url was correct at time of publication for .net 3.5 you may need to change this in future.
// local system for testing…
// dotnetRedistURL = ‘http: // 192.168 . 1.1 / dotnetfx35.exe’;
function InitializeSetup(): Boolean;
begin
Result : = true;
dotNetNeeded : = false;
sqlNeeded : = false;
sqlInstance: = false;
// Check for required netfx installation
if ( not RegKeyExists(HKLM, ‘Software\Microsoft\.NETFramework\AssemblyFolders\v3. 5 ′)) then begin
dotNetNeeded : = true;
if ( not IsAdminLoggedOn()) then begin
MsgBox(’GasSoft needs the Microsoft .NET Framework to be installed by an Administrator’, mbInformation, MB_OK);
Result : = false;
end else begin
memoDependenciesNeeded : = memoDependenciesNeeded + ‘ .NET Framework’ # 13 ;
dotnetRedistPath : = ExpandConstant(’ { src } \dotnetfx35.exe’);
if not FileExists(dotnetRedistPath) then begin
dotnetRedistPath : = ExpandConstant(’ { tmp } \dotnetfx35.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 ;
if ( not RegKeyExists(HKLM, ‘SOFTWARE\Microsoft\Microsoft SQL Server\ 90 \Tools’)) then begin
sqlNeeded : = true;
if ( not IsAdminLoggedOn()) then begin
MsgBox(’GasSoft needs Microsoft SQL Server to be installed by an administrator’, mbInformation, MB_OK);
Result : = false;
end else begin
memoDependenciesNeeded : = memoDependenciesNeeded + ‘ SQL Server Express 2005 ′ # 13 ;
sqlserverPath : = ExpandConstant(’ { src } \SQLEXPR32.EXE’);
end ;
end else begin
if ( not RegKeyExists(HKLM, ‘SOFTWARE\Microsoft\Microsoft SQL Server\YOURINSTACENAME‘)) then begin
sqlNeeded : = false;
sqlInstance : = true;
if ( not IsAdminLoggedOn()) then begin
MsgBox(’YOURAPPNAME needs Microsoft SQL Server to be installed by an administrator’, mbInformation, MB_OK);
Result : = false;
end else begin
memoDependenciesNeeded : = memoDependenciesNeeded + ‘ Add instance to SQL Server’ # 13 ;
sqlserverPath : = ExpandConstant(’ { src } \SQLEXPR32.EXE’);
end ;
end ;
end ;
end ;
function NextButtonClick(CurPage: Integer): Boolean;
var
hWnd: Integer;
ResultCode: Integer;
begin
Result : = true;
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
if downloadNeeded then begin
isxdl_SetOption(’ label ’, ‘Downloading Microsoft .NET Framework’);
isxdl_SetOption(’des - c - r - i - p - tion’, ‘YOURAPPNAME needs to install the Microsoft .NET Framework. Please wait while Setup is downloading extra files to your computer.’);
if isxdl_DownloadFiles(hWnd) = 0 then Result : = false;
end ;
if (Result = true) and (dotNetNeeded = true) then begin
if Exec(ExpandConstant(dotnetRedistPath), ‘ / qb’, ”, 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 ;
if (Result = true) and (sqlNeeded = true) and ( not sqlInstance = true) then begin
if Exec(ExpandConstant(sqlserverPath), ‘ / settings ‘ + ExpandConstant(’ { src } ’) + ’\setup.ini / qb’, ”, 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 ;
if (Result = true) and (sqlNeeded = false) and (sqlInstance = true) then begin
if Exec(ExpandConstant(sqlserverPath), ‘ / settings ‘ + ExpandConstant(’ { src } ’) + ’\setup.ini / qb’, ”, 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 ;
function UpdateReadyMemo(Space, NewLine, MemoUserInfoInfo, MemoDirInfo, MemoTypeInfo, MemoComponentsInfo, MemoGroupInfo, MemoTasksInfo: String): String;
var
s: string;
begin
if memoDependenciesNeeded <> ” then s : = s + ‘Dependencies to install:’ + NewLine + memoDependenciesNeeded + NewLine;
s : = s + MemoDirInfo + NewLine + NewLine;
Result : = s
end ;
You will find that some of the s - c - r - i - p - t (provided by unknown) cleverly checks to see if the .net files are included in the same directory “ { src } ” as the setup program , if not it runs a downloader program and downloads the required files. I have not adjusted the s - c - r - i - p - t to do this for SQL server as I did not deem this necessary, but if you struggle to make the changes yourself then feel free to contact me and I will try my best.
Now the s - c - r - i - p - t should compile and faultlessly install firstly the .net framework , and / or sql server express.
Highlighted in red are small sections you would need to change to customise this for your own use.