We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

bleachga
Posts: 2
Joined: Fri May 31, 2019 12:09 pm

Best Way to Write Property to a File

I'm wondering what the best/easiest way is to accomplish the following:

If (and only if) the user provides a command line property, e.g. LICENSEKEY=value, I would like Advanced Installer to write the value to a file, e.g. [CommonAppData] /MyCompany/MyProduct/license.dat.

Do I need a custom action for this? Is there an example/tutorial like this anywhere?

Thanks in advance,

-brian
Catalin
Posts: 7853
Joined: Wed Jun 13, 2018 7:49 am

Re: Best Way to Write Property to a File

Hello Brian and welcome to Advanced Installer forums,

No, we do not have a sample for this, but I can help you achieve it.

First thing we want to know here is the fact that a property can have only two states:

1. it has a value => it exists

2. it does not exist

Yes, you are right, this can be achieved through a custom action. For instance, a PowerShell script that adds some content to a text file looks like this:

Code: Select all

Add-Content "path_to_your_text_file" "text_to_be_appended"
We have said discussed above about the two states that a property has. This will be helpful for our condition that will determine if the custom action will execute or not.

Let's consider the following property: MY_PROP

Property exists ==> the condition is: MY_PROP

Property does not exist ==> the condition is: NOT MY_PROP

In our case, the condition will be "MY_PROP".

The above script can be added in Advanced Installer as a "PowerShellScriptInline" custom action.

The custom action content may look something as it follows: (added after the "#your code goes here" comment)

Code: Select all

$myProp = AI_GetMsiProperty MY_PROP

# the above line simply gets the value of MY_PROP property and stores it in the $myProp variable.

Add-Content "C:\Users\Catalin\Desktop\test.txt" "$myProp"
Under "Execution Stage Condition" field, the condition may look something as it follows:

Code: Select all

(VersionNT > 501) OR (VersionNT = 501 AND ServicePackLevel >= 2) AND MY_PROP
Now you can run the following command:

Code: Select all

msiexec /i <path_to_msi> MY_PROP="SomeValue"

and the value of your property ("SomeValue") should be added to the text file.

Hope this helps.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
bleachga
Posts: 2
Joined: Fri May 31, 2019 12:09 pm

Re: Best Way to Write Property to a File

Thank you! That got me far enough to make it happen.
Catalin
Posts: 7853
Joined: Wed Jun 13, 2018 7:49 am

Re: Best Way to Write Property to a File

You are always welcome.

Glad to help.

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

Return to “Building Installers”