Emmanuel
Posts: 17
Joined: Fri Mar 05, 2021 4:01 pm

How to add a custom action in a project using Powershell Automation?

Fri Mar 05, 2021 4:53 pm

Is it possible to add a custom action in a project using Powershell Automation ? (https://www.advancedinstaller.com/user- ... ation.html)
The custom action have to be executed in deferred execution with the conditions &FeatureName=3 (for example)

Thank you for your help.

Catalin
Posts: 4108
Joined: Wed Jun 13, 2018 7:49 am

Re: How to add a custom action in a project using Powershell Automation?

Fri Mar 05, 2021 6:29 pm

Hello Emmanuel and welcome to our forums,

Yes, it is possible to add a custom action to your project through our PowerShell Automation support. This feature has been added in version 17.0 of Advanced Installer.

Most likely you did not find this because we do not currently have an article about it in our User Guide. I have created a ticket for our Technical Writing team to develop an article about this feature.

Please note, however, that not all custom actions are supported (i.e. you can not add all the Custom Action types).

Here is a sample PowerShell for what you need:

Code: Select all

$advinst = new-object -comObject "AdvancedInstaller"
$proj    = $advinst.CreateProjectS("architect")
$file = $proj.FilesComponent.AddFileS("appdir", "C:\Users\Catalin\Desktop\sample.exe")
$ca = $proj.CustomActionsComponent.NewLaunchInstalledFile($file)

# Custom Action Options

$ca.CommandLine = "-cmd"
$ca.ExecuteSequenceCondition = "1"
$ca.ExecutionTime = "Deferred"
$ca.FailInstallationIfReturnsError = $true
$ca.RunUnderLocalSystemAccount = $true
$ca.WaitToFinish = $true
Hope this helps!

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

Emmanuel
Posts: 17
Joined: Fri Mar 05, 2021 4:01 pm

Re: How to add a custom action in a project using Powershell Automation?

Fri Mar 05, 2021 6:53 pm

Thank you for your help Catalin. Impatient to read the new article ;)

Emmanuel
Posts: 17
Joined: Fri Mar 05, 2021 4:01 pm

Re: How to add a custom action in a project using Powershell Automation?

Mon Mar 08, 2021 10:13 am

Hello,

I tried to create a custom action that execute a Powershell script file. This is my code:

Code: Select all

$advinst = New-Object -ComObject AdvancedInstaller
$project = $advinst.CreateProjectS("architect")

$project.ProductDetails.Name = "myProduct"

$project.ProductDetails.Version = "1.0.1"
$project.ProductDetails.Publisher = "Publisher"

$project.SaveAs("C:\Users\Administrator\Desktop\AutomationAI.aip")

$file = $project.FilesComponent.AddFileS("appdir", "C:\Users\Administrator\Desktop\MyCusto.ps1")


$ca = $project.CustomActionsComponent.NewLaunchInstalledScriptFile($file)

# Custom Action Options
$ca.ScriptType = "Powershell"
$ca.ExecuteSequenceCondition.Condition = "&MainFeature=3"
$ca.ExecutionTime = "Deferred"
$ca.FailInstallationIfReturnsError = $true
$ca.RunUnderLocalSystemAccount = $true
$ca.WaitToFinish = $true

$project.Save()
But it seems "Powershell" type is not available:

PS C:\Users\Administrator> C:\Users\Administrator\Desktop\Test_AI_Automation.ps1
Saved successfully
Supported types values are: javascript javascript64 vbscript vbscript64

At C:\Users\Administrator\Desktop\Test_AI_Automation.ps1:17 char:1
+ $ca.ScriptType = "Powershell"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException


Saved successfully


Is there another way to do that or this feature is not available yet?

Catalin
Posts: 4108
Joined: Wed Jun 13, 2018 7:49 am

Re: How to add a custom action in a project using Powershell Automation?

Mon Mar 08, 2021 2:59 pm

Hello,

As I have mentioned in my previous thread, unfortunately, not all custom actions types are currently supported.

As for this moment, it is not possible to add a PowerShell custom action through our PowerShell automation support.

I will, however, add this on our TODO list on improvements regarding the PowerShell Automation feature and hopefully this will be available in a future version of Advanced Installer.

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

Emmanuel
Posts: 17
Joined: Fri Mar 05, 2021 4:01 pm

Re: How to add a custom action in a project using Powershell Automation?

Mon Mar 08, 2021 3:05 pm

Ok, thank you for your answer. Hope this will be available in the version 18.1 :-)

Catalin
Posts: 4108
Joined: Wed Jun 13, 2018 7:49 am

Re: How to add a custom action in a project using Powershell Automation?

Mon Mar 08, 2021 3:08 pm

You are always welcome, Emmanuel!

I can not give you an ETA on when this will be available, but I will update this thread as soon as it will.
:)

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

Catalin
Posts: 4108
Joined: Wed Jun 13, 2018 7:49 am

Re: How to add a custom action in a project using Powershell Automation?

Thu Apr 01, 2021 1:35 pm

Hello Emmanuel,

I have done a bit more research/testing on this feature and we might actually have support for what you need.

If I understand correctly, you want to add a new "PowerShellScriptFile" custom action (e.g. PowerShell custom action executed from a .ps1 file).

If that is the case, you might want to have a look over the following:

Code: Select all

$ca = $proj.CustomActionsComponent.NewPowershellAttachedScriptFile($file)
This way, you no longer need to specify the $ca.SCriptType parameter.

The "NewLaunchInstalledScriptFile" actually refers to either a JScript or VBScript custom action, as it is mentioned in the error message as well:
Supported types values are: javascript javascript64 vbscript vbscript64
Hope this helps!

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

Return to “Building Installers”