How to install SQL Server 2008 Express with Inno Setup? - 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. :)

Related

AddProduct and isX64 functions not recognized in 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.

InstallShield 2015 setup and update env path on Windows 10

I’m using InstallShield 2015 SP1 with Basic MSI project
When installing my setup on Windows 10 machine, it seems that restart or logoff is needed for the path environment variable to be updated.
The path is updated with the .ism file under Environment Variables,
I tried using custom action that run this InstallScript code ( taken from InstallShield help ) to avoid restart but it didn’t helped, Any ideas ?
#define WM_WININICHANGE 0x001A
#define HWND_BROADCAST 0xffff
STRING szKey, szEnv;
WPOINTER pEnv;
begin
// Flush the registry to all applications.
szEnv = "Environment";
pEnv = &szEnv;
SendMessage (HWND_BROADCAST, WM_WININICHANGE, 0, pEnv );
end;
Just need to put the CA after InstallFinalize.

Inno Setup CreateOleObject('IISNamespace') throws exception on Windows Server 2012

I am trying to create IISSetup in the Windows Server 2012 (IIS version 8.5) through the below install script but throws error "Invalid class string".
code:
var
IIS, WebSite, WebServer, WebRoot, VDir: Variant;
ErrorCode: Integer;
begin
{ Create the main IIS COM Automation object }
try
IIS := CreateOleObject('IISNamespace');
except
RaiseException(
'Please install Microsoft IIS first.'#13#13'(Error ''' +
GetExceptionMessage + ''' occurred)');
end;
end;
I had the same issue on a Windows Server 2008 R2 Enterprise with Service Pack 1.
procedure TForm1.Button1Click(Sender: TObject);
var
iis: OleVariant;
begin
iis := CreateOleObject('IISNamespace');
end;
The solution for me was a missing IIS feature. One has to install the IIS 6 thingy.
(germany version, don't know english)
IIS 6-Verwaltungskompatibilität
IIS 6-Metabasiskompatibilität
IIS 6-WMI-Kompatibilität
IIS 6-Scriptingtools
IIS 6-Verwaltungskonsole
I am not sure but "IIS 6-Scriptingtools" should be enough.

After installing SQL Server Express 2008 R2 using SQLEXPRWT_x86_ENU.exe, SQL Server can't create database

I have an NSIS install script which successfully installs an instance of SQL Server Express 2008 R2 on Windows 7, but when I later try to create a database from the install script I get an error saying access denied. My detailed steps follow.
I install SQL Server Express with my NSIS installer using the following:
ExecWait 'SQLEXPRWT_x86_ENU.exe /Q /ACTION=Install /IACCEPTSQLSERVERLICENSETERMS /ROLE=AllFeatures_WithDefaults /SQLSVCACCOUNT="NT AUTHORITY\Network Service" /INSTANCENAME=SQLXXXX /SecurityMode=SQL /SAPWD="xxxxxx" /IndicateProgress'
Then within my NSIS installer I 'try' to create a database with the following:
ExecWait 'sqlcmd -S "computerName\SQLXXXX" -i "$OUTDIR\ASPNETDB_Create.SQL" -o "$OUTDIR\ASPNETDB_Create_Log.txt"'
The script ASPNETDB_Create.SQL fails at the first command in it which follows:
CREATE DATABASE [aspnetdb] ON PRIMARY
( NAME = N'aspnetdb', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLXXXX\MSSQL\DATA\aspnetdb.mdf' , SIZE = 411392KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
LOG ON ( NAME = N'aspnetdb_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLXXXX\MSSQL\DATA\aspnetdb_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
I get the following error listed:
CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLXXXX\MSSQL\DATA\aspnetdb.mdf'.
It seems the problem is that the folder 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLXXXX\MSSQL\DATA' doesn't have any permissions set for user "NT AUTHORITY\Network Service".
If incorrect access permissions are indeed my problem, how can I set the correct permissions on the DATA directory where the database will reside?
You can change the ACL with the AccessControl plugin

Is it possible to send parameters to InstallShield prerequisites?

I am evaluating InstallShield 2010, and am trying to set some command line parameters to the SQL Server 2008 prerequisite at user runtime. It appears that the prerequisite is defined entirely in the .prq files (xml-style).
Wise for Windows used WiseScript to call the prerequisite installations. InstallAware seems to have something similar, with their own scripting. Does something similar exist for InstallShield?
We use IS v12; I built a .prq file for the purpose (they don't supply a .prq for SQL 2008 for IS v12). First I went to http://msdn.microsoft.com/en-us/library/ms144259.aspx to get all possible cmd line args. Then I used the IS PRQ editor to create the basic .prq structure. Then I hand-edited the .prq (xml) file for (a) easy minor adjustments in the future and (b) to simplify version control diffs.
<?xml version="1.0" encoding="utf-8"?>
<SetupPrereq>
<conditions>
<condition Type="16" Comparison="2" Path="[ProgramFilesFolder]Microsoft SQL Server\100\COM" FileName="sqlresld.dll" ReturnValue="2007.100.1600.22"/>
</conditions>
<files>
<file LocalFile="<ISProductFolder>\SetupPrerequisites\Microsoft SQL Server 2008 Express with Tools\SQLEXPRWT_x86_ENU.exe" CheckSum="BCC335711D44BAFC420B5165D2F04647" FileSize="0,229169680"/>
</files>
<execute file="SQLEXPRWT_x86_ENU.exe" requiresmsiengine="1"
cmdline ="/INSTANCEID=AV /INSTANCENAME=AV /ACTION=Install /FEATURES=SQLENGINE,SSMS /HELP=0 /ERRORREPORTING=0 /SQMREPORTING=0 /INDICATEPROGRESS=0 /QUIETSIMPLE=1 /FILESTREAMLEVEL=0 /ENABLERANU=1 /TCPENABLED=1 /NPENABLED=0 /ADDCURRENTUSERASSQLADMIN=1 /AGTSVCACCOUNT="NT AUTHORITY\NETWORK SERVICE" /AGTSVCSTARTUPTYPE=Manual /BROWSERSVCSTARTUPTYPE=Automatic /SQLSVCSTARTUPTYPE=Automatic /SQLSVCACCOUNT="NT AUTHORITY\NETWORK SERVICE" /RSSVCSTARTUPTYPE=Automatic"
cmdlinesilent="/INSTANCEID=AV /INSTANCENAME=AV /ACTION=Install /FEATURES=SQLENGINE,SSMS /HELP=0 /ERRORREPORTING=0 /SQMREPORTING=0 /INDICATEPROGRESS=0 /QUIETSIMPLE=1 /FILESTREAMLEVEL=0 /ENABLERANU=1 /TCPENABLED=1 /NPENABLED=0 /ADDCURRENTUSERASSQLADMIN=1 /AGTSVCACCOUNT="NT AUTHORITY\NETWORK SERVICE" /AGTSVCSTARTUPTYPE=Manual /BROWSERSVCSTARTUPTYPE=Automatic /SQLSVCSTARTUPTYPE=Automatic /SQLSVCACCOUNT="NT AUTHORITY\NETWORK SERVICE" /RSSVCSTARTUPTYPE=Automatic"
/>
<dependencies>
<dependency File="<ISProductFolder>\SetupPrerequisites\Microsoft Installer 4.5 for XP.prq"/>
<dependency File="<ISProductFolder>\SetupPrerequisites\Microsoft Installer 4.5 for Windows Server 2003 or 64 bit XP.prq"/>
<dependency File="<ISProductFolder>\SetupPrerequisites\Power Shell 1.0 for Windows XP.prq"/>
<dependency File="<ISProductFolder>\SetupPrerequisites\Power Shell 1.0 for Windows Server 2003.prq"/>
</dependencies>
<properties Id="Microsoft SQL Server 2008 Express with Tools" Description="This installs Microsoft SQL Server 2008 Express Edition (SQL Server Express). The /qn switch suppresses all Setup dialog boxes and error messages. See http://msdn2.microsoft.com/en-us/library/ms144259.aspx for more information about the commad line options. The SQL setup logs to %programfiles%\Microsoft SQL Server\100\Setup Bootstrap\Log\"/>
</SetupPrereq>
Yes - by right clicking on the SQL Server prerequisite -> "Application to Run"' tab -> "Specify the command line for the application".
The only way I know how to do this is to write a Helper.EXE that the PRQ calls. The EXE would need to detect the windows settings and silently pass the correct arguments to the real Prereq EXE/MSI.

Resources