Check if prerequisite is present before install application

Hello guys,

Anyone has already coded a function to check if the prerequisite is installed before running the installation ?
I will be great if its possible to check if prerequisite is installed and if not the prerequisite is installed then the main application is installed too just after.

Any Idea ?
I think I can check if registry key exist to see if the prerequisite is installed and if not, I call the prerequisite PS file to install it.

Thank you

Arnaud

As per Page 47 of the manual:

If you need to test for existence of a registry key path, use the built-in Test-Path cmdlet.

There is no PSADT-created for PreRequisites.
Sorry.

All right,

Do you have an idea how I can call another PS1 ?

    $Prerequisite = Get-RegistryKey -Key "HKEY_LOCAL_MACHINE\SOFTWARE\packages\Oracle ODBC" -Value '(Default)'
	if ($Prerequisite -ne $PrerequisiteSignature) {
	Show-InstallationProgress -StatusMessage "Prerequisite is not installed ! `nCalling Prerequisite Installation Script"
	Write-Log -Message "Prerequisite is not installed. Starting Installation..." -Source "Check-Prerequisite" -LogType 'Legacy'
	Execute-Process -Path "$PSHOME\powershell.exe" -parameters "-File ""$dirFiles\Deploy-Application_Prerequisite.ps1""" -WindowStyle Hidden
	} Else {}
	Show-InstallationProgress -StatusMessage "Prerequisite is installed ! `nContinuing"

The Deploy-Application_Prerequisite.ps1 are in the same folder than Deploy-Application.ps1
If I put Deploy-Application_Prerequisite.ps1 into Files and Run the command with the $dirFiles\Deploy-Application_Prerequisite.ps1 it’s works but I need to copy AppDeployToolkit into Files too because if this folder do not exist in Files the called file AppDeployToolkitMain.ps1 is not found.

Module does not exist at the specified location [XXX\Files\AppDeployToolkit\AppDeployToolkitMain.ps1

Whats the “best” Solution for me except copy the AppDeployToolkit into Files folder

Because you have effectively 2 packages, one calling the other, you cannot share PowerShell sessions.(Parent’s Variables would get changed by the child)

Since you want Deploy-Application_Prerequisite.ps1 to be hidden, this will work:
[string]$MyArguments = “-ExecutionPolicy Bypass -NoLogo -File”$dirFiles\Deploy-Application_Prerequisite.ps1" "
Execute-Process -FilePath “powershell.exe” -Arguments $MyArguments -ContinueOnError $False -CreateNoWindow #No separate window, Only parent. Child is hidden

If you want to see both as separate consoles:
[string]$MyArguments = “-ExecutionPolicy Bypass -NoLogo -File”$dirFiles\Deploy-Application_Prerequisite.ps1" "
Try {
$Myprocess = start-process -FilePath “$PSHOME\powershell” -ArgumentList $MyArguments -Wait -PassThru #Works but no exitcode handling
#CAVEAT: to use redirection, all parameters redirect to a file ONLY! #e.g. -RedirectStandardOutput
#But we don’t need it b/c Deploy-Application_Prerequisite.ps1 does all this by itself and has it’s own logs.
$Myprocess.WaitForExit() #wait for it to finish
$ExitCode=$Myprocess.ExitCode #must be AFTER .WaitForExit() method
If ($Myprocess) { $Myprocess.Dispose() } # Clear memory

Write-Log -Message  "Prerequisite script returned `$ExitCode = $ExitCode"
If ( 0 -match $ExitCode) {
	Write-Log -Message  "Deploy-Application_Prerequisite.ps1 was successful."
} ElseIf (-1073741510 -match $ExitCode) {
	Write-Log -Message  "ERROR: User closed Prerequisite's Powershell Console window"
	# CAVEAT Exitcode -1073741510 can become %ErrorLevel% 314 (Quad -> Dword)
	Exit-Script -ExitCode $ExitCode	#No prereq, no main package
} else {
	Write-Log -Message  "Deploy-Application_Prerequisite.ps1 Failed."
	Exit-Script -ExitCode $ExitCode
}

} Catch {
If ([string]::IsNullOrEmpty([string]$returnCode)) {
[int32]$returnCode = 60002
Write-Log -Message “start-process failed, setting exit code to [$returnCode]. n$(Resolve-Error)" -Severity 3 -Source $deployAppScriptFriendlyName } Else { Write-Log -Message "start-process completed with exit code [$returnCode]. Function failed.n$(Resolve-Error)” -Severity 3 -Source $deployAppScriptFriendlyName
}
Exit-Script -ExitCode $returnCode
}

WARNING: WordPress cannot handle Backticks and changes SOME straight double quotes to curly double quotes.

And now, I can’t edit my post. So let’s try this.

Since you want Deploy-Application_Prerequisite.ps1 to be hidden, this will work:

[string]$MyArguments = "-ExecutionPolicy Bypass -NoLogo -File (BackTick)"$dirFiles\Deploy-Application_Prerequisite.ps1(BackTick)" "
Execute-Process -FilePath "powershell.exe" -Arguments $MyArguments -ContinueOnError $False -CreateNoWindow #No separate window, Only parent. Child is hidden

Just replace (BackTick) with the ASCII 96