Returning a string from a script - Advanced Installer Community
toschlog
Posts: 26
Joined: Fri Jun 10, 2011 5:39 pm

Returning a string from a script

I'm trying to create a shortcut that contains the version number of my project. I started with "MyApp v[|ProductVersion]" as the name of the shortcut.

But now I'd like to change it to use only the first two parts of the version number (eg., "1.2" instead of "1.2.0"). To do this I created a new property called ProductVersionShort and created a custom action that calls VBS code, like this:

Function GetVersionNumberShort()
fullVersion = Session.Property("ProductVersion")
'get trimmed version
Session.Property("ProductVersionShort") = trimmedVersion
End Function

The code runs without error, but the value of ProductVersionShort isn't changed after my function is called. Any ideas?

Thanks.
Dan
Posts: 4530
Joined: Wed Apr 24, 2013 3:51 pm

Re: Returning a string from a script

Hello,
I'm trying to create a shortcut that contains the version number of my project. I started with "MyApp v[|ProductVersion]" as the name of the shortcut.
Please note that the name of a shortcut can be at least referenced by a PseudoFormatted data type and it will be resolved at build time.
As a workaround you can add your own deferred custom action that will set the shortcut name with the value of ProductVersionShort property. You can add this custom action in the “Install Execution Stage” >> “Add Resources” action group.
You can also take a look on Custom Action Properties article which may be useful to you.
But now I'd like to change it to use only the first two parts of the version number (eg., "1.2" instead of "1.2.0"). To do this I created a new property called ProductVersionShort and created a custom action that calls VBS code, like this:

Function GetVersionNumberShort()
fullVersion = Session.Property("ProductVersion")
'get trimmed version
Session.Property("ProductVersionShort") = trimmedVersion
End Function

The code runs without error, but the value of ProductVersionShort isn't changed after my function is called. Any ideas?
It seems ok your script code. Please make sure that you set the ProductVersionShort property with the desired value, only the first two fields, so make sure the trimmedVersion property only contains the first two fields of the ProductVersion.
You can also take a look on the following code:

Code: Select all

MsgBox Session.Property("ProductVersion")

Session.Property("test") = Left(Session.Property("ProductVersion"), InStrRev(Session.Property("ProductVersion"), ".")-1)

MsgBox Session.Property("test")
Please note that the script code was used in an Execute inline script predefined custom action with sequence. You can add this custom action in “Install Execution Stage” >> “Searches” action group. You can also duplicate it in the “Wizard Dialogs Stage” by a drag-and-drop operation while the “SHIFT” key is pressed. You can also edit its Advanced execution Scenarios properties.

If you have any more questions, please let us know.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
toschlog
Posts: 26
Joined: Fri Jun 10, 2011 5:39 pm

Re: Returning a string from a script

I think the problem is that the shortcut name is resolved at build time, and my script is updating the property at install time. Is there any way to get my script to run at build time?

For now I have a script that renames the shortcut at the end of the installation, but that doesn't feel like the right solution.
Dan
Posts: 4530
Joined: Wed Apr 24, 2013 3:51 pm

Re: Returning a string from a script

Hello,
I think the problem is that the shortcut name is resolved at build time, and my script is updating the property at install time.
As I said before, the shortcut name is PsudorFormatted data type and it will be resolved at build time.
For now I have a script that renames the shortcut at the end of the installation, but that doesn't feel like the right solution.
As you can see in my previos reply, this is the workaround.
I'm trying to create a shortcut that contains the version number of my project. I started with "MyApp v[|ProductVersion]" as the name of the shortcut.
Please note that the name of a shortcut can be at least referenced by a PseudoFormatted data type and it will be resolved at build time.
As a workaround you can add your own deferred custom action that will set the shortcut name with the value of ProductVersionShort property. You can add this custom action in the “Install Execution Stage” >> “Add Resources” action group.
You can also take a look on Custom Action Properties article which may be useful to you.
If you have any questions, please let us know.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”