AddProduct and isX64 functions not recognized in Inno Setup - inno-setup

Trying to call a subscript to install MS SQL server as part of an Inno Setup.
In the main script I include the subscript in the run section and call the procedure with the BeforeInstall:
[Run]
#include "MSSQLExpress2014WithTools.iss";
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent; BeforeInstall: sql2014express()
So far so good, but it seems like Inno Setup dislike my MSSQLExpress2014WithTools.iss subscript:
[CustomMessages]
sql2014expressx86_title=Microsoft SQL Server 2014 Express Edition x86 (Including Tools)
sql2014expressx64_title=Microsoft SQL Server 2014 Express Edition x64 (Including Tools)
sql2014expressx86_size=840.8 MB
sql2014expressx64_size=833.2 MB
[Code]
const
sql2014expressx86_url='http://download.microsoft.com/download/E/A/E/EAE6F7FC-767A-4038-A954-49B8B05D04EB/ExpressAndTools%2032BIT/SQLEXPRWT_x86_ENU.exe';
sql2014expressx64_url='http://download.microsoft.com/download/E/A/E/EAE6F7FC-767A-4038-A954-49B8B05D04EB/ExpressAndTools%2064BIT/SQLEXPRWT_x64_ENU.exe';
procedure sql2014expresswithtools();
var
version: string;
begin
{ Check if the full version fo the SQL Server 2014 is installed }
RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\Microsoft SQL Server\SQLSERVER\MSSQLServer\CurrentVersion', 'CurrentVersion', version);
if (version < '12') or (version = '') then
begin
{ If the full version is not found then check for the Express edition }
RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\Microsoft SQL Server\SQLEXPRESS\MSSQLServer\CurrentVersion', 'CurrentVersion', version);
if (version < '12') or (version = '') then
begin
if isX64() then AddProduct('SQLEXPRWT_x64_ENU.exe', '/QS /IACCEPTSQLSERVERLICENSETERMS /ACTION=Install /FEATURES=SQL,AS,RS,IS,Tools /INSTANCENAME=SQLEXPRESS /SQLSVCACCOUNT="NT AUTHORITY\Network Service" /SQLSYSADMINACCOUNTS="builtin\Administrators" /INDICATEPROGRESS /TCPENABLED=1 /BROWSERSVCSTARTUPTYPE=Automatic /ERRORREPORTING=0 /SQMREPORTING=0 /SECURITYMODE=SQL /SAPWD=1234', CustomMessage('sql2014expressx64_title'), CustomMessage('sql2014expressx64_size'), sql2014expressx64_url,false,false)
else AddProduct('SQLEXPRWT_x86_ENU.exe', '/QS /IACCEPTSQLSERVERLICENSETERMS /ACTION=Install /FEATURES=SQL,AS,RS,IS,Tools /INSTANCENAME=SQLEXPRESS /SQLSVCACCOUNT="NT AUTHORITY\Network Service" /SQLSYSADMINACCOUNTS="builtin\Administrators" /INDICATEPROGRESS /TCPENABLED=1 /BROWSERSVCSTARTUPTYPE=Automatic /ERRORREPORTING=0 /SQMREPORTING=0 /SECURITYMODE=SQL /SAPWD=1234', CustomMessage('sql2014expressx86_title'), CustomMessage('sql2014expressx86_size'), sql2014expressx86_url,false,false);
end;
end;
end;
It doesn't recognize the AddProduct and isX64 functions.
Any hints appreciated!

There's no AddProduct or isX64 function in Inno Setup.
You have probably based your code on some example, that uses some Inno Setup extension/addon, which adds these functions.
I assume the addon is Inno Setup Dependency Installer, as it indeed defines functions with these names.

Related

Perform DeleteFile only on NEW installation [duplicate]

My InnoSetup script opens a web page (with the user's default browser) at the end of the install process:
[Run]
Filename: http://example.com; Flags: shellexec
However, I'd like the web page to not be opened if the app already exists, i.e., if the user is installing a new version of the program. The web page should only be opened after the initial install. (I assume it's worth mentioning that the install includes an AppID, obviously, and enters values in the registry beside installing files.)
Thank you, as always -- Al C.
Yes, this is easy to do with scripting.
Just write
[Run]
Filename: "http://example.com"; Flags: shellexec; Check: NotAnUpdate
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpInstalling then
IsUpdate := FileExists(ExpandConstant('{app}\TheFileNameOfMyApp.exe'));
end;
function NotAnUpdate: Boolean;
begin
result := not IsUpdate;
end;
The answer by #AndreasRejbrand won't work, if user chooses to install the executable to a different location than the last time.
You can query installer-specific Inno Setup registry keys:
#define AppId "your-app-id"
#define SetupReg \
"Software\Microsoft\Windows\CurrentVersion\Uninstall\" + AppId + "_is1"
#define SetupAppPathReg "Inno Setup: App Path"
[Setup]
AppId={#AppId}
...
[Run]
Filename: "https://www.example.com/"; Flags: shellexec; Check: not IsUpgrade
...
[Code]
function IsUpgrade: Boolean;
var
S: string;
begin
Result :=
RegQueryStringValue(HKLM, '{#SetupReg}', '{#SetupAppPathReg}', S) or
RegQueryStringValue(HKCU, '{#SetupReg}', '{#SetupAppPathReg}', S);
end;
For an example how to use IsUpgrade in [Code] section, see
Excludes part of Code section in ssPostInstall step if installation is update in Inno Setup
Check this if your "AppId" contains a left-curly-bracket:
Checking if installation is fresh or upgrade does not work when AppId contains a curly bracket

Inno Setup - Register components as an administrator

Based on the excellent Excel add-in installer (Daniel's XL Toolbox), I have built a setup file that among other things needs to register some ActiveX's
[Files]
; The include file makes adds all .XLA and .XLAM files contained in the
; SOURCEDIR to the project.
Source: "c:\source\path\MSCOMCTL.OCX"; \
DestDir: "\users\public\EzPasteFiles"; Flags: regserver
Source: "c:\source\path\DAS_AX_Knob.dll"; \
DestDir: "\users\public\EzPasteFiles"; Flags: regserver
Source: "c:\source\path\GIF89.DLL"; \
DestDir: "\users\public\EzPasteFiles"; Flags: regserver
I need the addin to install, then before starting to register the files a check is done about administrator rights and if the user has none, a message is displayed asking for entering the admin password so that registration can take place. I am aware that it can be done at the beginning of the setup, but then the addin will not be activated, if it is a standard user account. The addin needs registered components, a standard user can't install it properly.
I am looking for something like this to fire before the registration starts:
MyProgChecked := not(IsAdminLoggedOn or IsPowerUserLoggedOn);
if MyProgChecked = True then
begin
MsgBox(
'Kindly notice:' #13#13
'It seems as you are not looged as an administrator' #13#13
'Please abort and reinstall EzPaste AS an administrator' #13#13
'(To install As an Adminstrator, just save the exe setup anywhere then Right Click on it to get to this feature or ask your IT administrator for proper directives)',
mbConfirmation, MB_OK);
{ Popup message asking for Pwd }
ExitProcess(0);
end;
I am naturally open for any other approach
I'll be glad also to understand how a domain user (Windows server) without admin rights should proceed to install the addin.
You can execute regsvr32.exe "as administrator", this way:
[Files]
Source: "MyDll.dll"; DestDir: "{app}"; AfterInstall: RegMyDll
[Code]
procedure RegMyDll;
var
Path: string;
RegSvr: string;
Params: string;
Registered: Boolean;
ErrorCode: Integer;
begin
Path := ExpandConstant(CurrentFilename);
RegSvr := 'regsvr32.exe';
Params := Format('/s "%s"', [Path]);
Log(Format('Registering %s using "%s" %s', [Path, RegSvr, Params]));
Registered :=
ShellExec('runas', RegSvr, Params, '', SW_HIDE, ewWaitUntilTerminated, ErrorCode);
if Registered and (ErrorCode = 0) then
begin
Log(Format('Registered %s', [Path]));
end
else
begin
MsgBox(Format('Registering %s failed with code %d', [Path, ErrorCode]), mbError, MB_OK);
end;
end;
Alternative implementation is to create subinstaller for the registration only that will require Administrator privileges.
For a similar example, see Inno Setup - Access unprivileged account folders from installer that requires privileges.
Or use an opposite approach. Require administrator privileges using
[Setup]
PrivilegesRequired=admin
(which is default)
But deploy files to the original user folder.
See my answer to Inno Setup always installs into admin's AppData directory.

Inno Setup: Install file from Internet

I am using Inno Setup to distribute my application.
Is it possible to check in Inno Script for a particular condition and download and install some file from internet if required.
Inno Setup 6.1 and newer has a built-in support for downloads. No 3rd party solution are needed anymore.
Check the Examples\CodeDownloadFiles.iss in Inno Setup installation folder.
The important parts of the example are:
[Files]
; These files will be downloaded
Source: "{tmp}\innosetup-latest.exe"; DestDir: "{app}"; Flags: external
Source: "{tmp}\ISCrypt.dll"; DestDir: "{app}"; Flags: external
[Code]
var
DownloadPage: TDownloadWizardPage;
function OnDownloadProgress(const Url, FileName: String; const Progress, ProgressMax: Int64): Boolean;
begin
if Progress = ProgressMax then
Log(Format('Successfully downloaded file to {tmp}: %s', [FileName]));
Result := True;
end;
procedure InitializeWizard;
begin
DownloadPage := CreateDownloadPage(SetupMessage(msgWizardPreparing), SetupMessage(msgPreparingDesc), #OnDownloadProgress);
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
if CurPageID = wpReady then begin
DownloadPage.Clear;
DownloadPage.Add('https://jrsoftware.org/download.php/is.exe', 'innosetup-latest.exe', '');
DownloadPage.Add('https://jrsoftware.org/download.php/iscrypt.dll', 'ISCrypt.dll', '2f6294f9aa09f59a574b5dcd33be54e16b39377984f3d5658cda44950fa0f8fc');
DownloadPage.Show;
try
try
DownloadPage.Download;
Result := True;
except
SuppressibleMsgBox(AddPeriod(GetExceptionMessage), mbCriticalError, MB_OK, IDOK);
Result := False;
end;
finally
DownloadPage.Hide;
end;
end else
Result := True;
end;
For alternatives, see Running a program after it is downloaded in Code section in Inno Setup
Inno Download Plugin by Mitrich Software.
It's an InnoSetup script and DLL, which allows you to download files as part of your installation.
It supports FTP, HTTP and HTTPS.
It's kind of a drop-in replacement for InnoTools Downloader. Only few changes required.
It brings a decent download display and HTTPS and Mirror(s) support.
Example:
#include <idp.iss>
[Files]
Source: "{tmp}\file.zip"; DestDir: "{app}"; Flags: external; ExternalSize: 1048576
[Code]
procedure InitializeWizard();
begin
idpAddFileSize('http://127.0.0.1/file.zip', ExpandConstant('{tmp}\file.zip'), 1048576);
idpDownloadAfter(wpReady);
end.
Yes, there is a library called InnoTools Downloader which has samples that do pretty much this. They can be conditioned on anything you want using normal Inno code.
Found on Inno 3rd Party is one very similar in scope and style to the Inno Download Plugin, DWinsHs.
Included with an easy and intuitive chm file which requires unblocking to view.

Can Inno Setup respond differently to a new install and an update?

My InnoSetup script opens a web page (with the user's default browser) at the end of the install process:
[Run]
Filename: http://example.com; Flags: shellexec
However, I'd like the web page to not be opened if the app already exists, i.e., if the user is installing a new version of the program. The web page should only be opened after the initial install. (I assume it's worth mentioning that the install includes an AppID, obviously, and enters values in the registry beside installing files.)
Thank you, as always -- Al C.
Yes, this is easy to do with scripting.
Just write
[Run]
Filename: "http://example.com"; Flags: shellexec; Check: NotAnUpdate
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpInstalling then
IsUpdate := FileExists(ExpandConstant('{app}\TheFileNameOfMyApp.exe'));
end;
function NotAnUpdate: Boolean;
begin
result := not IsUpdate;
end;
The answer by #AndreasRejbrand won't work, if user chooses to install the executable to a different location than the last time.
You can query installer-specific Inno Setup registry keys:
#define AppId "your-app-id"
#define SetupReg \
"Software\Microsoft\Windows\CurrentVersion\Uninstall\" + AppId + "_is1"
#define SetupAppPathReg "Inno Setup: App Path"
[Setup]
AppId={#AppId}
...
[Run]
Filename: "https://www.example.com/"; Flags: shellexec; Check: not IsUpgrade
...
[Code]
function IsUpgrade: Boolean;
var
S: string;
begin
Result :=
RegQueryStringValue(HKLM, '{#SetupReg}', '{#SetupAppPathReg}', S) or
RegQueryStringValue(HKCU, '{#SetupReg}', '{#SetupAppPathReg}', S);
end;
For an example how to use IsUpgrade in [Code] section, see
Excludes part of Code section in ssPostInstall step if installation is update in Inno Setup
Check this if your "AppId" contains a left-curly-bracket:
Checking if installation is fresh or upgrade does not work when AppId contains a curly bracket

How to install SQL Server 2008 Express with Inno Setup?

anyone have script or procedures to install SQL Server 2008 Express, set up the database for the app and finally install a client .NET WinForm application?
In situations like this where I'm relying on third-party products (SQL Server Express), I tend to use command-line driven installs (either directly in a cmd file or called from a 'proper' install tool). This site shows you how to install Express from the command line, then you can use the SQL Express utility for object creation. This method is 'blessed' by Microsoft.
Sometimes the simplest solution is the best, even if that means getting the user of my product to install SQL Express separately before running my install. Well, best for me, anyway :-)
The following script will check for the full version of SQL Server 2008 R2. If full version is already installed, then it skips installing the SQL Server. If the full version is not installed, then it checks for the SQL Express edition. If it is already installed, it will skip the installation. If it is not installed, then it will install SQL Express 2008 R2.
Create a new script. Let's name it sql2008express.iss with the following content
[CustomMessages]
sql2008r2expressx86_title=Microsoft SQL Server 2008 R2 Express Edition x86 (Including Tools)
sql2008r2expressx64_title=Microsoft SQL Server 2008 R2 Express Edition x64 (Including Tools)
sql2008r2expressx86_size=235.5 MB
sql2008r2expressx64_size=247.5 MB
[Code]
const
sql2008r2expressx86_url='http://download.microsoft.com/download/5/5/8/558522E0-2150-47E2-8F52-FF4D9C3645DF/SQLEXPRWT_x86_ENU.exe';
sql2008r2expressx64_url='http://download.microsoft.com/download/5/5/8/558522E0-2150-47E2-8F52-FF4D9C3645DF/SQLEXPRWT_x64_ENU.exe';
procedure sql2008express();
var
version: string;
begin
// Check if the full version fo the SQL Server 2008 R2 is installed
RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\Microsoft SQL Server\SQLSERVER\MSSQLServer\CurrentVersion', 'CurrentVersion', version);
if (version < '10.5') or (version = '') then begin
// If the full version is not found then check for the Express edition
RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\Microsoft SQL Server\SQLEXPRESS\MSSQLServer\CurrentVersion', 'CurrentVersion', version);
if (version < '10.5') (*or (version > '9.00') or (version = '') *) then begin
if isX64() then
AddProduct('SQLEXPRWT_x64_ENU.exe', '/QS /IACCEPTSQLSERVERLICENSETERMS /ACTION=Install /FEATURES=SQL,AS,RS,IS,Tools /INSTANCENAME=SQLEXPRESS /SQLSVCACCOUNT="NT AUTHORITY\Network Service" /SQLSYSADMINACCOUNTS="builtin\Administrators" /INDICATEPROGRESS /TCPENABLED=1 /BROWSERSVCSTARTUPTYPE=Automatic /ERRORREPORTING=0 /SQMREPORTING=0 /SECURITYMODE=SQL /SAPWD=1234', CustomMessage('sql2008r2expressx64_title'), CustomMessage('sql2008r2expressx64_size'), sql2008r2expressx64_url,false,false)
else
AddProduct('SQLEXPRWT_x86_ENU.exe', '/QS /IACCEPTSQLSERVERLICENSETERMS /ACTION=Install /FEATURES=SQL,AS,RS,IS,Tools /INSTANCENAME=SQLEXPRESS /SQLSVCACCOUNT="NT AUTHORITY\Network Service" /SQLSYSADMINACCOUNTS="builtin\Administrators" /INDICATEPROGRESS /TCPENABLED=1 /BROWSERSVCSTARTUPTYPE=Automatic /ERRORREPORTING=0 /SQMREPORTING=0 /SECURITYMODE=SQL /SAPWD=1234', CustomMessage('sql2008r2expressx86_title'), CustomMessage('sql2008r2expressx86_size'), sql2008r2expressx86_url,false,false);
end;
end;
end;
In your script then just include the script i nthe [Run] tag and call the previous created script in the [Code] tag like below:
[Run]
`#include "scripts\sql2008express.iss"
[Code]
sql2008express();
Other notes:
- If the setup kits for the SQL are found in the same folder then it will use them, if not, they will be downloaded from the Internet.
- Sorry for the formating, it doesn't work. Copy/paste it in a text editor and format it. It is complete and working.
I hope this will help others too. :)

Resources