alext72
Posts: 11
Joined: Fri Nov 18, 2016 9:56 am

powershell automation customaction

Hello,

I'm trying to automate the creation of an MSI using PowerShell and the Advanced Installer COM interface.
The MSI should contain three custom actions, two at install and one at uninstall.

I'm having trouble with the execution order of the two install-time custom actions.

Here’s a simplified version of my PowerShell script:

Code: Select all

Write-Output "Creating Advanced Installer project"
$advinst = New-Object -ComObject AdvancedInstaller
$project = $advinst.CreateProjects("architect")

$project.ProductDetails.Name = $packageData.packageName
$project.ProductDetails.Publisher= $packageData.VendorInfo.vendor
$project.ProductDetails.Version= $packageData.VendorInfo.version

#retrieve source Folder
Write-Output "Copy zxp into exmancmd folder : workingFolder\$packageName\ExmanCmd"
$normalizedZxpName = $packageName + ".zxp"
Copy-Item  -path $workingFolder\$installerName -destination $workingFolder\$packageName\ExmanCmd\$normalizedZxpName
$sourceFolder = (get-item $workingFolder\$packageName\ExmanCmd).FullName
Write-Output "Source Folder for msi file is : $sourceFolder"

#Add files
Write-Output "Adding all files to project"
$project.FilesComponent.AddFolderContents("appdir", "$sourceFolder")

#Set msi as 64 bits
Write-Output "Set msi as 64 bits"
$project.InstallParameters.PackageType = "amd64"
$project.InstallParameters.ApplicationFolder = "[ProgramFiles64Folder]\[ProductName]"

write-Output "Set control panel icon"
$project.ProductDetails.SetIcon("$workingFolder\$packageName\package.ico")





$exmanCmdFile = $project.FilesComponent.FindFileByPath("APPDIR\exmancmd.exe")
$zxpFile = $project.FilesComponent.FindFileByPath("APPDIR\$normalizedZxpName")




$removeActionName = "ExmanCmdRemoveatAtInstall"
Write-Output "Defining '$removeActionName' custom action for finish sequence"

$custActRemoveAtInstall = $project.CustomActionsComponent.NewLaunchInstalledFile($exmanCmdFile)
$custActRemoveAtInstall.ExecuteSequenceCondition.Uninstall = $false
$custActRemoveAtInstall.Name = $removeActionName
$custActRemoveAtInstall.WaitToFinish = $true
$custActRemoveAtInstall.FailInstallationIfReturnsError = $false
$custActRemoveAtInstall.RunUnderLocalSystemAccount = $true
$custActRemoveAtInstall.CommandLine = "/remove com.Mypanel"


$custActRemoveAtInstall.CreateExecuteSequence("InstallFinalize")
Write-Output "'$removeActionName' is scheduled after 'InstallFinalize'."



$installActionName = "ExmanCmdInstall"
Write-Output "Defining '$installActionName' custom action for finish sequence"

$custActInstall = $project.CustomActionsComponent.NewLaunchInstalledFile($exmanCmdFile)
$custActInstall.ExecuteSequenceCondition.Uninstall = $false
$custActInstall.Name = $installActionName
$custActInstall.WaitToFinish = $true
$custActInstall.RunUnderLocalSystemAccount = $true
$custActInstall.CommandLine = "/install `"[#myPanel.zxp]`""


Write-Output "Chaining '$installActionName' to run after '$removeActionName'..."
$custActInstall.CreateExecuteSequence($removeActionName)
Write-Output "Chaining complete."


$custActRemoveAtUnInstall = $project.CustomActionsComponent.NewLaunchInstalledFile($exmanCmdFile)
$custActRemoveAtUnInstall.ExecuteSequenceCondition.Uninstall = $true
$custActRemoveAtUnInstall.ExecuteSequenceCondition.Maintenance = $false
$custActRemoveAtUnInstall.ExecuteSequenceCondition.FirstInstall =$false
$custActRemoveAtUnInstall.ExecuteSequenceCondition.Upgrade = $false
$custActRemoveAtUnInstall.Name = "ExmanCmdRemoveatAtUnInstall"
$custActRemoveAtUnInstall.WaitToFinish = $true
$custActRemoveAtUnInstall.FailInstallationIfReturnsError =$true
$custActRemoveAtUnInstall.RunUnderLocalSystemAccount = $true
$custActRemoveAtUnInstall.CommandLine = "/removecom.Mypanel"


# --- Code for saving the project ---
Write-Output "Saving project"
$project.SaveAs("$workingFolder\$packageName.aip")


When I open the .aip file in the Advanced Installer GUI, I can see that:

ExmanCmdInstall is executed before ExmanCmdRemoveAtInstall.

In the “Install Execution Sequence” view, ExmanCmdInstall has sequence number 6402, while ExmanCmdRemoveAtInstall has 6403.

What I need is for ExmanCmdRemoveAtInstall to run first, before ExmanCmdInstall.

Is there a way (via the COM API) to explicitly set a sequence number or order for install-time custom actions?

Any help would be greatly appreciated.

Thanks!
Catalin
Posts: 7530
Joined: Wed Jun 13, 2018 7:49 am

Re: powershell automation customaction

Hello Alexandre,

In order to schedule a custom action, we need to first remove its' sequence (using "RemoveExecuteSequence" method) and then recreate it (using "CreateExecuteSequence").

So, for your specific example, it looks like this:

Code: Select all

$custActInstall.RemoveExecuteSequence()
$custActInstall.CreateExecuteSequence("CreateFolders")
This way, the custom action will be scheduled after the "CreateFolders" standard action.

The "CreateExecuteSequence" method accepts as a parameter a string which consists of the name of the action after which you want to schedule it.
Screenshot_76.png
Screenshot_76.png (20.75 KiB) Viewed 585 times

Hope this helps!

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
alext72
Posts: 11
Joined: Fri Nov 18, 2016 9:56 am

Re: powershell automation customaction

Hello Catlin,

I will try and let you know.
Also how can I list all available standard actions like "CreateFolders" ?

Best regards,
Alexandre
Catalin
Posts: 7530
Joined: Wed Jun 13, 2018 7:49 am

Re: powershell automation customaction

Hell Alexandre,

You are always welcome!

Regarding the standard actions, I'm afraid that can not be achieved as for this moment.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”