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

Retrieve version of multiple EXEs

Mon Sep 23, 2019 2:55 pm

Hello guys,

A user recently asked me if it is possible to get the version of multiple EXEs and set an installer property to the value of the EXE's version. Something similar with the "Set version from file..." option from the "Product Details" page - when you right click on the "Version:" field.

Although we do not have predefined support for such a task, it is still possible. This is mostly possible with the help of "Pre and Post Build Events", more specifically with the help of a pre-build event. With that being said, I have decided to make a "How-To" for this, in case other users will need this in the future.

Basically, here we will need a PowerShell script (a .BAT file, EXE, VBScript can be used as well) which will:

- take the version from the EXE (EXEs) and store it in a variable (variables).

- further use that variable to set a property to the variable's value using the "/SetProperty" command option.

For the sake of the example, I have used the "RepackagerCLI.exe" and "updater.exe" which are available in every version of Advanced Installer. These can be found in the installation folder of Advanced Installer, at the following path:

Code: Select all

..\Caphyon\Advanced Installer\Advanced Installer <version>\bin\x86\ExeName.exe
For instance, the "updater.exe" path on my machine is the following:

Code: Select all

C:\Program Files (x86)\Caphyon\Advanced Installer 16.3\bin\x86\updater.exe
Here are the steps that can be followed in order to achieve this:

- in "Install Parameters" page, create one property for each of your EXE. E.g.:

1. REPACKAGER_VERSION
2. UPDATER_VERSION

both with their values blank. Also, for both, please add comments as this is the only way to "initialize" an empty property.

Below you can find the script that takes the version from an EXE and stores it in a property:

Code: Select all

# Script that can be used as a pre-build event in order to get the "Version" attribute of an EXE and store it in a property. We can further use this property
# to write the version value in the registries.

# As a prerequisite, please create the proeprties in your project with empty values (in order to create a property with an empty value, simply add a comment to it).

$AICom = "C:\Program Files (x86)\Caphyon\Advanced Installer 16.3\bin\x86\AdvancedInstaller.com"
$projectPath = "C:\Users\Catalin\Desktop\Retrieve version from multiple EXEs.aip"
$repackagerPath = "C:\Program Files (x86)\Caphyon\Advanced Installer 16.3\bin\x86\RepackagerCLI.exe"
$updaterPath = "C:\Program Files (x86)\Caphyon\Advanced Installer 16.3\bin\x86\updater.exe"

# get the version from the Repackager and store it in a variable
# the below cmdlet will return a string, which will look something like this: 1, 0, 0, 0. We will further use the "Replace()" method to replace the "," with "."
$repackagerVer = (get-item -path $repackagerPath).VersionInfo.FileVersion.Replace(',','.')
$updaterVer = (get-item -path $updaterPath).VersionInfo.FileVersion.Replace(',','.')

# now that we have got the version of the EXEs, we will further set the properties that we created in our project.

Start-Process -FilePath $AICom -ArgumentList "/edit `"$projectPath`" /SetProperty REPACKAGER_VERSION=`"$repackagerVer`""
Start-Sleep -Seconds 2
Start-Process -FilePath $AICom -ArgumentList "/edit `"$projectPath`" /SetProperty UPDATER_VERSION=`"$updaterVer`""
Start-Sleep -Seconds 2
Start-Process -FilePath $AICom -ArgumentList "/save"
Copy the above script and save it in a PowerShell script file (.ps1). Now please:


- open your project (if it's not already opened)

- go to "Builds" page and create a pre-build event (right click --> "Add" --> "Pre-Build Event" --> "New...")

The event should look like this:

Command: powershell.exe
Arguments: -ExecutionPolicy Bypass "&""C:\Users\Catalin\Desktop\VersionScript.ps1"""


Here, you should just replace the path with the path where your script resides.

Now, at Build time, the script will be executed and then the properties will be set. Here are the steps that need to be taken:

- build the project - the pre-build event will take place

- close your project

- re-open your project. At this point, you can check the "Install Parameters" page - here you will notice that the properties were populated accordingly.

- re-build the project. Now the properties will be added in the MSI database as well. Upon install, you can go and check the registries, there you should see the values being set accordingly.


Also, please find below an archive that contains an AIP file and the script which hopefully will help you achieve those said above:
Hope this helps.

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

Hokum_52

Re: Retrieve version of multiple EXEs

Sat Dec 14, 2019 8:57 am

Awesome, that's what I was looking for! I tried and tried to do it myself but it didn't really work, so thanks for that step-by-step explanation, I wouldn't have been able to find other .exe files otherwise..

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

Re: Retrieve version of multiple EXEs

Mon Dec 16, 2019 9:05 am

Hello,

Thank you for your kind feedback on this.

I am really glad this was of help for you.

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

Return to “Sample Projects”