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!