gazunk
Posts: 3
Joined: Mon Aug 23, 2021 11:21 pm

PowerShell build problems

Mon Aug 23, 2021 11:37 pm

Hi,

I'm trying to build an installer from scratch using Powershell, for use in a multi-project CI system. I am following this tutorial: https://www.advancedinstaller.com/user- ... ation.html

This simple script fails:

Code: Select all

$project = $advinst.CreateProjects("professional")
$project.ProductDetails.Name="$PROJECT_TITLE"
$project.ProductDetails.Publisher="Company Limited"
$project.ProductDetails.Version="$PROJECT_VERSION"

$project.FilesComponent.AddFolderContentS("APPDIR","build\bin")
$project.FilesComponent

$project.SaveAs("Installer.aip")
Firstly,

Code: Select all

$project.FilesComponent
does not list any files (or any information) as the tutorial suggests it should.

Then, saving the project produces this error message:

Code: Select all

Error opening file: "Installer.aip".

At <script location>
+ $project.SaveAs("Installer.aip")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException

This occurs on 18.4 and 18.5

The documentation for ProductCode also seems confusing (GetProductCode and UpdateProductCode "Adds a new file in the project and returns the file as an object"?): https://www.advancedinstaller.com/user- ... tcode.html

Liviu
Posts: 1026
Joined: Tue Jul 13, 2021 11:29 am
Contact:  Website

Re: PowerShell build problems

Tue Aug 24, 2021 10:55 am

Hello and welcome to our forums,
Firstly,

Code: Select all

$project.FilesComponent
does not list any files (or any information) as the tutorial suggests it should.
The correct command here is "$project.FilesComponent.Files" as detailed in our tutorial.
Then, saving the project produces this error message:
This error appears because you don't give the path of the location where you want the project to be saved. You need to use:

Code: Select all

$project.SaveAs(“C:\Sample\Installer.aip”)

Also, the first command should be "$advinst = New-Object -ComObject AdvancedInstaller" to create a new COM object of type Advanced Installer.
This is your script adapted:

Code: Select all

$advinst = New-Object -ComObject AdvancedInstaller
$project = $advinst.CreateProjects("professional")
$project.ProductDetails.Name="Test"
$project.ProductDetails.Publisher="Company Limited"
$project.ProductDetails.Version="1.0.0"

$project.FilesComponent.AddFolderContents("APPDIR","D:\test powershell cmd\resources")
$project.FilesComponent.Files
$project.SaveAs(“D:\test powershell cmd\Installer.aip”)
The documentation for ProductCode also seems confusing (GetProductCode and UpdateProductCode "Adds a new file in the project and returns the file as an object"?):
Indeed, the documentation is misleading. I’m sorry for that, we will update it.
The correct command here is:

Code: Select all

$project.ProductDetails.ProductCode.GetProductCode()

Hope this helps! If you have any other questions, please don't hesitate to contact us.

Best regards,
Liviu
________________________________________
Liviu Sandu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

gazunk
Posts: 3
Joined: Mon Aug 23, 2021 11:21 pm

Re: PowerShell build problems

Tue Aug 24, 2021 6:46 pm

Thanks for the reply! I did instantiate $advinst, but it looks like you called the other errors correctly, ta.

Liviu
Posts: 1026
Joined: Tue Jul 13, 2021 11:29 am
Contact:  Website

Re: PowerShell build problems

Tue Aug 24, 2021 7:15 pm

You are always welcome!

Please let us know if there is anything else we could help you with and we will gladly assist.

Best regards,
Liviu
________________________________________
Liviu Sandu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

SZLMCL
Posts: 26
Joined: Mon Nov 16, 2020 2:18 pm

Re: PowerShell build problems

Tue Mar 21, 2023 3:31 pm

Hello,

After I update AI to the latest version, the COM object call throws an exception:

$advinst = new-object -ComObject AdvancedInstaller

0x80040154 (R
EGDB_E_CLASSNOTREG)

Before install new version it worked fine.

How can I register the AI COM object manually to make this work again?

Thank you!

Liviu
Posts: 1026
Joined: Tue Jul 13, 2021 11:29 am
Contact:  Website

Re: PowerShell build problems

Tue Mar 21, 2023 4:24 pm

Hello,

Usually, AI COM uses the latest version installed on the system.

To register the latest AI version you want to use for COM, please follow these steps:

  1. Open an elevated Command Prompt.
    • Use the following command:

      Code: Select all

      "C:\Program Files (x86)\Caphyon\Advanced Installer 20.4.1\bin\x86\advinst.exe" /REGSERVER
      Use upper-case letters for "/REGSERVER".

      If you want to use another AI version, just use the above command. Go to the version you want to use and you can find the advinst.exe in "\bin\x86\".
      • Restart the PowerShell session and now you can build with the 20.4.1 version inside your script.
      Hope this helps! If you have any other questions, please don't hesitate to contact us.

      Best regards,
      Liviu
      ________________________________________
      Liviu Sandu - Advanced Installer Team
      Follow us: Twitter - Facebook - YouTube

      SZLMCL
      Posts: 26
      Joined: Mon Nov 16, 2020 2:18 pm

      Re: PowerShell build problems

      Tue Mar 21, 2023 4:29 pm

      Liviu wrote:
      Tue Mar 21, 2023 4:24 pm
      Hello,

      Usually, AI COM uses the latest version installed on the system.

      To register the latest AI version you want to use for COM, please follow these steps:

      1. Open an elevated Command Prompt.
        • Use the following command:

          Code: Select all

          "C:\Program Files (x86)\Caphyon\Advanced Installer 20.4.1\bin\x86\advinst.exe" /REGSERVER
          Use upper-case letters for "/REGSERVER".

          If you want to use another AI version, just use the above command. Go to the version you want to use and you can find the advinst.exe in "\bin\x86\".
          • Restart the PowerShell session and now you can build with the 20.4.1 version inside your script.
          Hope this helps! If you have any other questions, please don't hesitate to contact us.

          Best regards,
          Liviu
          Works fine, thank you!

          Liviu
          Posts: 1026
          Joined: Tue Jul 13, 2021 11:29 am
          Contact:  Website

          Re: PowerShell build problems

          Wed Mar 22, 2023 8:30 am

          You're always welcome!

          It's great to hear that everything is now working as expected.

          Best regards,
          Liviu
          ________________________________________
          Liviu Sandu - Advanced Installer Team
          Follow us: Twitter - Facebook - YouTube

          Return to “Building Installers”