[custom action] - Generating a file at install time - Advanced Installer Community

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!

Nico-D
Posts: 63
Joined: Mon Aug 18, 2008 2:34 pm

[custom action] - Generating a file at install time

Hello,

I need to generate a file at install time, using a VB Script. I have tested it, and it works and give the results I was looking for. But I do not know how to integrate it into the MSI.

The script is calling:
- a system command-line ([SystemFolder]hostname.exe)
- a shipped EXE, which will be installed into [APPDIR]my_bin.exe

I need to create the file into [APPDIR].

I am using a "File attached to installation" CA.

When attaching the CA to CostFinalize, the properties ([APPDIR], [SystemFolder], etc.) are well known and usable through

Code: Select all

Session.Property("APPDIR")
call. But the [APPDIR] is not yet created, and I cannot output to [APPDIR]...

When attaching the CA to Install, InstallFiles, Commit, ... the file is created into the [SystemFolder]...

Could you please give me a tip, as I do not perfectly understand when the Session variables are still accessible or not? Is it possible to do this? Is there another way?

Best regards,
-- Nicolas D.
Nico-D
Posts: 63
Joined: Mon Aug 18, 2008 2:34 pm

Re: [custom action] - Generating a file at install time

One precision: to make it work when the CA is attached to "Install", I am hardcoding the paths to hostaneme.exe, and I am using a local copy of my_bin.exe. Then the text file is created into my [SystemFolder].

-- Nicolas D.
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: [custom action] - Generating a file at install time

Hi,

The install process executes multiple standard actions which represent the installation. Windows Installer passes through these standard actions twice:
- the first time it includes them in an execution script if their conditions allow; this is when "Immediate" custom actions are executed
- the second time it executes them by using the script; this is when "Deferred", "Rollback" and "Commit" custom actions are executed

During the installation only Immediate custom actions have access to installer properties. However, the "CreateFolders" standard action is executed as "Deferred", when the installer properties are no longer available. Therefore, your Immediate custom actions cannot access APPDIR because it wasn't created yet.

A solution for this is to run your custom action as Deferred. Since you cannot use properties in it, you can pass the properties through the "Action Data" field in the Custom Action Properties page. These properties can then be retrieved inside the custom action from the CustomActionData property. Please note that the Write text into a file how-to uses this method, perhaps it can help you.

Let me know if this doesn't solve the problem.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Nico-D
Posts: 63
Joined: Mon Aug 18, 2008 2:34 pm

Re: [custom action] - Generating a file at install time

Hi Cosmin,

Thanks for your explanations about Custom Actions scheduling.
A solution for this is to run your custom action as Deferred. Since you cannot use properties in it, you can pass the properties through the "Action Data" field in the Custom Action Properties page. These properties can then be retrieved inside the custom action from the CustomActionData property. Please note that the Write text into a file how-to uses this method, perhaps it can help you.
The tutorial you pointed out is very interesting and discusses exactly what I want to do. Nevertheless, I am getting troubles with the very first steps:
First you need to add the file into the Files and Folders page in the folder you want to install it.
I have imported a new empty text file in the "Files and Folders" menu.
or this, you go to the Custom Actions page and create a new Property Source custom action under InstallExecuteSequence -> Install. The custom action can use these fields:

* Property Name: SERIAL_FILE
* Formatted Text: [APPDIR]serial.txt
* Expression: NOT Installed
Everything is OK, but the "Formatted Text" field does not exist. I used "Action Data" field instead, as you mentioned it in your reply. Moreover, what is the "Source Type" I have to set for the "Property Source"? VBS and JS are the only choices to get the "Action Data" field displayed.

I am sorry to bother you with a tutorial...

Regards,
-- Nicolas D.
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: [custom action] - Generating a file at install time

Hi,
Everything is OK, but the "Formatted Text" field does not exist.
I apologize for this, the article contains a mistake: it should say "Property set with Formatted" instead of "Property Source". This will be corrected as soon as possible.
what is the "Source Type" I have to set for the "Property Source"?
A "Property Source" custom action runs an EXE, VBS or JS file with its path given by a property (for example the property of a file search).

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Nico-D
Posts: 63
Joined: Mon Aug 18, 2008 2:34 pm

Re: [custom action] - Generating a file at install time

Hi Cosmin,

Thanks for your reply and don't worry for the mistake.

I finally succeeded in writing into the file in the [APPDIR] directory, thanks to you and the tutorial.
Nevertheless, I spent a lot of time on understanding why (token(0)) -see the tutorial- was empty. The solution is (evident): the "Property set with Formatted" must be located before the "File attached to installation". My mistake, because I tried many methods, and "File attached to installation" CA was before the other CA.

Maybe it could be a great thing for further users to set a warning in the tutorial, if you have to edit it?

Hope this helps, and many thanks,
-- Nicolas D.
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: [custom action] - Generating a file at install time

Hi,
Maybe it could be a great thing for further users to set a warning in the tutorial, if you have to edit it?
Yes, of course. We will also add a warning for this. Thank you for your suggestion.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”