Find path to a program (sqlcmd) installed by child subinstaller of Inno Setup - inno-setup

In my scenario I need to run .sql script at the end of my setup with sqlcmd.exe. But each version of SQL Server uses different paths for sqlcmd.
I'm trying some solutions to use sqlcmd but none work.
As a last test I created an installer just to run my script but even this doesn't recognize sqlcmd as a command.
Is there a way to retrieve the sqlcmd path with a function in order to pass the value to [Run] section?
Any suggestions are welcome.
Thanks
This is my code I'm trying
Main installer.exe
[Setup]
PrivilegesRequired=admin
[Files]
; sql server 2019 Express
Source: "..\PREREQUIREMENTS\SQL\SQLSERVER\2019\SQLEXPR_x64_ENU.exe"; \
DestDir: "{tmp}"; DestName: "SQLSERVER2019.exe"; Flags: ignoreversion; \
MinVersion: 10.0.17134; Tasks: SQL
; sql server 2014 Express
Source: "..\PREREQUIREMENTS\SQL\SQLSERVER\2014\SQLEXPR_x64_ENU.exe"; \
DestDir: "{tmp}"; DestName: "SQLSERVER2014SP3.exe"; Flags: ignoreversion; \
OnlyBelowVersion: 10.0.17134; Tasks: SQL
; sql management studio 18
Source: "..\PREREQUIREMENTS\SQL\SSMS\SSMS-Setup-ENU.exe"; DestDir: "{tmp}"; \
DestName: "SSMS18.exe"; Flags: ignoreversion; Tasks: SSMS
; SQLCMD
Source: "src\DB\ADM_DB_installer.exe"; DestDir: "{tmp}"; Flags: ignoreversion; \
Components: ADM
ADM_DB_installer.exe
[Setup]
PrivilegesRequired=admin
[Run]
Filename: "sqlcmd.exe"; \
Parameters: "-v ADMPRIMARY=""{code:GetSQLVar|DBPATH}"" ADMDATA=""{code:GetSQLVar|DBPATH}"" ADMINDEX=""{code:GetSQLVar|DBPATH}"" ADMLOG=""{code:GetSQLVar|DBPATH}"" -S {code:GetSQLVar|SQLSERVER}\{code:GetSQLVar|INSTANCE} -U sa -P {code:GetSQLVar|SAPWD} -i ""{tmp}\CREATE_ADM_DB_1.0.0.sql"" -o ""{code:GetSQLVar|DBPATH}\log.txt"""

There might be a better solution, but what you can do is to read the PATH from registry and use FileSearch to find the program.
[Run]
Filename: "{code:FileSearchInPath|sqlcmd.exe}"; Parameters: "..."
[Code]
const
EnvironmentKey = 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment';
function FileSearchInPath(FileName: string): string;
var
Path: string;
begin
Result := '';
if not RegQueryStringValue(HKLM, EnvironmentKey, 'PATH', Path) then
begin
Log('Cannot read PATH');
end
else
begin
Log(Format('PATH is %s', [Path]));
Result := FileSearch(FileName, Path);
if Result = '' then
begin
Log(Format('Cannot find %s', [FileName]));
end
else
begin
Log(Format('Found %s', [Result]));
end;
end;
if Result = '' then Result := FileName; // let it fail later
end;
The above code searches only system PATH, not user PATH.
You do not need a separate installer to execute the sqlcmd.exe.

Related

Unpack SFX file using Inno Setup

I'm trying to run Inno Setup to automatically extract my SFX file without having to run extract manually. Is there any way? I leave my script below.
Is there also a way to make Inno Setup extract the SFX in the Myprogramfolder created by the installer?
I have compressed the SFX file using Winrar.
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "Program2019"
#define MyAppVersion "1.0"
#define MyAppPublisher "Myappname."
#define MyAppURL "/"
[Setup]
WizardImageFile=C:\Users\Administrator\Desktop\Cover.bmp
; NOTE: The value of AppId uniquely identifies this application.
AppID={{31D336CF-0483-4A76-00000000000000000}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
DefaultDirName={pf}\Myprogram2019
DefaultGroupName={#MyAppName}
LicenseFile=C:\Users\Administrator\Desktop\Program2019\readme.txt
OutputDir=C:\Users\Administrator\Desktop\Program2019\Myprografolder
OutputBaseFilename=setup
SetupIconFile=C:\Users\Administrator\Desktop\Program2019\Myprogram\icon.ico
Compression=none
SolidCompression=true
InternalCompressLevel=Fast
[Languages]
Name: "english"; MessagesFile: "compiler:Languages\English.isl"
Name: "spanish"; MessagesFile: "compiler:Languages\Spanish.isl"
[Files]
Source: "C:\Program Files (x86)\Myprogramfolder\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "C:\Users\Administrator\Desktop\Program2019\Unpack\Evilpack.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall
Source: "C:\Users\Administrator\Desktop\Program2019\languages\spanish\*"; DestDir: "{app}\game"; Languages: spanish; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Run]
Filename: "{tmp}\Evilpack.exe"; Parameters: "{tmp}\ZipFile.ZIP -d C:\TargetDir"
[Icons]
Name: "{group}\{cm:ProgramOnTheWeb,{#MyAppName}}"; Filename: "{#MyAppURL}"
Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
Name: "{commondesktop}\Myprogram2019"; Filename: "{app}\mypro.exe"; IconFilename: {app}\icon.ico; \
AfterInstall: SetElevationBit('{commondesktop}\Myprogram.lnk')
[Code]
{ RedesignWizardFormBegin } // Don't remove this line!
// Don't modify this section. It is generated automatically.
procedure RedesignWizardForm;
begin
{ ReservationBegin }
// This part is for you. Add your specialized code here.
{ ReservationEnd }
end;
[Messages]
BeveledLabel=Myapp
Is very easy unpack in silent way SFX, setup to silent from the menu option ADVANCED, then SFX options in winrar.
That is all!!
Finally
[Files]
Source: "C:\pathtofile\yoursfx.exe"; DestDir: "C:\Program Files\";Flags: ignoreversion
[Run]
Filename: "C:\Program Files\yoursfx.exe"; StatusMsg: "Your MSG"; Flags: runascurrentuser
[Code]
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssDone then
begin;
DeleteFile(ExpandConstant('C:\Program Files\yoursfx.exe'));
begin
// user clicked Yes
end;
end;
end;

How to complete instalation ant then restart windows?

I try to rework existing inno setup script and include some dependencies to it. But at the middle of installation VC++ redistributable always restart the windows not from installing wizard window. And this restart totally has broken all installation progress. I have this script.
[Files]
Source: "E:\engine\repos\AACPsychologue_all\aacpsychologue\Installers\Launcher\AAC Psychologue.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "E:\engine\repos\AACPsychologue_all\aacpsychologue\Installers\Launcher\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "E:\engine\repos\AACPsychologue_all\aacpsychologue\Installers\Resources\dxwebsetup.exe"; DestDir: "{app}"; AfterInstall: DirecXinstaller; Flags: ignoreversion deleteafterinstall
Source: "E:\engine\repos\AACPsychologue_all\aacpsychologue\Installers\Resources\Windows6.1-KB2670838-x64.msu"; DestDir: "{app}"; Flags: 64bit deleteafterinstall
Source: "E:\engine\repos\AACPsychologue_all\aacpsychologue\Installers\Resources\Windows6.1-KB2670838-x86.msu"; DestDir: "{app}"; AfterInstall: Win7Update; Flags: 32bit deleteafterinstall
Source: "E:\engine\repos\AACPsychologue_all\aacpsychologue\Installers\Resources\Windows6.1-KB2670838-x86.msu"; DestDir: "{app}"; AfterInstall: Win7Update; Flags: 32bit deleteafterinstall
Source: "E:\engine\repos\AACPsychologue_all\aacpsychologue\Installers\Resources\vc_redist.x86.exe"; DestDir: "{app}";AfterInstall: vcInstaller; Flags: 32bit deleteafterinstall
Source: "E:\engine\repos\AACPsychologue_all\aacpsychologue\Installers\Resources\vc_redist.x64.exe"; DestDir: "{app}";AfterInstall: vcInstaller; Flags: 64bit deleteafterinstall
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}";
[Code]
procedure DirecXinstaller;
var
ResultCode: Integer;
begin
if not Exec(ExpandConstant('{app}\dxwebsetup.exe'), '', '', SW_SHOWNORMAL,
ewWaitUntilTerminated, ResultCode)
then
MsgBox('Other installer failed to run!' + #13#10 +
SysErrorMessage(ResultCode), mbError, MB_OK);
end;
procedure Win7Update;
var
ResultCode: Integer;
begin
if IsWin64 then
begin
Exec(ExpandConstant('{app}\Windows6.1-KB2670838-x64.msu'), '', '', SW_SHOWNORMAL,
ewWaitUntilTerminated, ResultCode)
end
else
begin
Exec(ExpandConstant('{app}\Windows6.1-KB2670838-x86.msu'), '', '', SW_SHOWNORMAL,
ewWaitUntilTerminated, ResultCode)
end;
end;
procedure vcInstaller;
var
ResultCode: Integer;
begin
if IsWin64 then
begin
Exec(ExpandConstant('{app}\vc_redist.x64.exe'), '', '', SW_SHOWNORMAL, ewNoWait, ResultCode)
end
else
begin
Exec(ExpandConstant('{app}\vc_redist.x86.exe'), '', '', SW_SHOWNORMAL, ewNoWait, ResultCode)
end;
end;
[Run]
Filename: "{app}\{#MyAppExeName}"; Flags: postinstall skipifsilent waituntilterminated unchecked;
Have any ideas?
vc_redist.*.exe have /norestart switch to prevent the restart.
You can then make Inno Setup restart the machine using AlwaysRestart directive.
Also, note that it is better to use [Run] section to execute the sub-installer. Additionally, it not a good practice to install temporary files to {app}. I also do not think that you want to use ewNoWait.
[Setup]
AlwaysRestart=yes
[Files]
Source: "...\vc_redist.x86.exe"; DestDir: "{tmp}"; Flags: 32bit
Source: "...\vc_redist.x64.exe"; DestDir: "{tmp}"; Flags: 64bit
[Run]
Filename: "{tmp}\vc_redist.x86.exe"; Parameters: "/norestart"; Flags: 32bit
Filename: "{tmp}\vc_redist.x64.exe"; Parameters: "/norestart"; Flags: 64bit

Inno Setup How to exclude a single file from AfterInstall

After install, I want to save a string to 3 out of the 4 files, but currently it's saving the string to all. How do I exclude a file called network? I'm thinking another if statement, but not sure how. This file would be {app}\configs\network.config
procedure MyBeforeInstall;
begin
if(FileExists(ExpandConstant(CurrentFileName))) then
begin
Exists := True;
end
else
begin
Exists := False;
end;
end;
procedure MyAfterInstall;
begin
if not(Exists) then
SaveStringToFile(ExpandConstant(CurrentFileName), #13#10 + 'SettingEnv ' + SettingEnv.Values[0] + #13#10, True);
MsgBox(ExpandConstant(CurrentFileName), mbInformation, MB_OK);
end;
Assuming you use MyBeforeInstall and MyAfterInstall like this:
[Files]
Source: "*.txt"; DestDir: "{app}"; \
BeforeInstall: MyBeforeInstall; AfterInstall: MyAfterInstall
Then you can do this instead:
[Files]
Source: "one.txt"; DestDir: "{app}"; \
BeforeInstall: MyBeforeInstall; AfterInstall: MyAfterInstall
Source: "two.txt"; DestDir: "{app}"; \
BeforeInstall: MyBeforeInstall; AfterInstall: MyAfterInstall
Source: "three.txt"; DestDir: "{app}"; \
BeforeInstall: MyBeforeInstall; AfterInstall: MyAfterInstall
Source: "but_not_this_one.txt"; DestDir: "{app}"
This will do too:
[Files]
Source: "*.txt"; Excludes: "but_no_this_one.txt"; DestDir: "{app}"; \
BeforeInstall: MyBeforeInstall; AfterInstall: MyAfterInstall
Source: "but_not_this_one.txt"; DestDir: "{app}"
Yet another option is:
procedure MyAfterInstall;
begin
if CompareText(ExtractFileName(CurrentFileName), 'but_not_this_one.txt') <> 0 then
begin
if not Exists then
SaveStringToFile(
CurrentFileName,
#13#10 + 'SettingEnv ' + SettingEnv.Values[0] + #13#10, True);
end;
MsgBox(CurrentFileName, mbInformation, MB_OK);
end;
(ntb, that there's no point using ExpandConstant on CurrentFileName, as its return value does not contain any constants)

How to selectively create a directory, copy files and run a batch file in InnoSetup [duplicate]

Alternatively is it possible to manually update the built in progress bar?
Basically I have 2 MSIs included and using Inno Setup as a bootstrapper, and depending on user input one or both of the MSIs are to be installed. I have something working using Exec statements in CurStepChanged but it doesn't update the progress bar as the files are extracted and it looks like the installer is stalled. I guess the end result is I want some progress bar updates while the files are extracted to the temp folder. The following is my current code:
procedure CurStepChanged(CurStep: TSetupStep);
var
ResultCode: Integer;
begin
if(CurStep = ssInstall) then begin
if(InstallServer) then begin
ExtractTemporaryFile('ServerSetup.msi');
Exec('msiexec',ExpandConstant('/i "{tmp}\ServerSetup.msi" /qb INSTALLDIR="{code:GetInstallPath}\Server\" ALLUSERS=2'),'', SW_SHOW, ewWaitUntilTerminated, ResultCode);
end;
if(InstallClient) then begin
ExtractTemporaryFile('ClientSetup.msi');
Exec('msiexec',ExpandConstant('/i "{tmp}\ClientSetup.msi" /qb INSTALLDIR="{code:GetInstallPath}\Client\" ALLUSERS=2'),'', SW_SHOW, ewWaitUntilTerminated, ResultCode);
end;
end;
end;
Why not simply try something like this:
[Files]
Source: ClientSetup.msi; DestDir: {tmp}; Flags: deleteafterinstall; Components: Client
Source: ServerSetup.msi; DestDir: {tmp}; Flags: deleteafterinstall; Components: Server
[Run]
Filename: msiexec.exe; Parameters: /i "{tmp}\ClientSetup.msi" /qb INSTALLDIR="{code:GetInstallPath}\Client\" ALLUSERS=2; WorkingDir: {tmp}; StatusMsg: Installing client; Components: Client
Filename: msiexec.exe; Parameters: /i "{tmp}\ServerSetup.msi" /qb INSTALLDIR="{code:GetInstallPath}\Server\" ALLUSERS=2; WorkingDir: {tmp}; StatusMsg: Installing server; Components: Server
[Components]
Name: Client; Description: Client Installation
Name: Server; Description: Server Installation
Of course you don't necessarily have to use Components. You did not write how you decide which installer to run. If you need more complex logic you could also use Check functions as in:
[Files]
Source: ClientSetup.msi; DestDir: {tmp}; Flags: deleteafterinstall; Check: CheckClient
Source: ServerSetup.msi; DestDir: {tmp}; Flags: deleteafterinstall; Check: CheckServer
[Run]
Filename: msiexec.exe; Parameters: /i "{tmp}\ClientSetup.msi" /qb INSTALLDIR="{code:GetInstallPath}\Client\" ALLUSERS=2; WorkingDir: {tmp}; StatusMsg: Installing client; Check: CheckClient
Filename: msiexec.exe; Parameters: /i "{tmp}\ServerSetup.msi" /qb INSTALLDIR="{code:GetInstallPath}\Server\" ALLUSERS=2; WorkingDir: {tmp}; StatusMsg: Installing server; Check: CheckServer
[Code]
function CheckClient: Boolean;
begin
Result := WhateverCondition;
end;
function CheckServer: Boolean;
begin
Result := WhateverOtherCondition;
end;

Invalid prototype when using a Check function

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;
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;
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;

Resources