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!

tmwoods
Posts: 11
Joined: Thu Dec 19, 2019 10:32 pm

Using Files and Folders during installation

My goal: to run a custom action during install that executes SQL scripts to update a database.
My problem: I can't access the Files and Folders contents during install.
More detail: We regularly generate hundreds of SQL scripts so using the manual SQL Script functionality in Advanced Installer isn't practical.
What I've tried: I can successfully execute my custom action (using C#) but when I attempt to read the files in the install folder they don't exist. If instead I use the temporary install directory, they aren't there either.

Using Folder Indentifier:

Code: Select all

string tablesFolder = session["Tables_Dir"]; // Gets correct final installation folder but contents are empty
Using Install Parameters:
I set a Property called SQLTABLESFOLDER its value is [APPDIR]SQLScripts\Tables.

Code: Select all

string tablesFolder = session["SQLTABLESFOLDER "]; // Returns a temp directory at C:|WINDOWS|INSTALLER|MSI721F.msi but files don't exist there either
So I guess my real question is: where are the contents of 'Files and Folders' during install? If, in my custom action, I want to access that folder, how do I do it?

Thanks!
Catalin
Posts: 7853
Joined: Wed Jun 13, 2018 7:49 am

Re: Using Files and Folders during installation

Hello and welcome to Advanced Installer forums,

The files from the "Files and Folders" page are copied on the target machine during the "Add resources" ("Custom Actions" page --> "Install Execution Stage" --> "Add Resources" action group, on the deferred stage.

With that being said, if you want to make use of a file (e.g. your SQL script) that is in the "Files and Folders" page, you will need to add your custom action after the "Add Resources" action group and set its execution time to "When the system is being modified (deferred)".

If you need to execute the custom action earlier, a solution may be to use our support for temporary files. Unlike Advanced Installer's regular files or resources, "Temporary Files" are copied on the target machine at the beginning of the installation and are deleted at the end of it, ensuring you have access to them throughout the entire install process.

Hope this helps.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
tmwoods
Posts: 11
Joined: Thu Dec 19, 2019 10:32 pm

Re: Using Files and Folders during installation

Hi Catalin,

Thanks for the reply. My custom action now throws an exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Microsoft.Deployment.WindowsInstaller.InstallerException: Cannot access session details from a non-immediate custom action
I moved the custom action after 'Add Resources' and set the execution time to 'When the system is being modified (deferred)'. Is there a way I can access the session variables at this time? Or is there another way I should 'know' the install paths at this point in the installation?

I see I can pass Action Data during a custom action but in deferred state it looks like you can only pass a single variable. I would need at least 4 to 6 string objects.

Thanks!
tmwoods
Posts: 11
Joined: Thu Dec 19, 2019 10:32 pm

Re: Using Files and Folders during installation

Hi Catalin,

Just to give as much info as possible - I have also tried using the Temporary Files option but the files do not exist in the path specified. In my custom action I have the following code:

Code: Select all

string tablesFolder = session["Tables_Dir"];
string spFolder = session["StoredProcedures_Dir"];
string functionsFolder = session["Functions_Dir"];

session.Log("ExecuteSQLScripts BEGIN");
session.Log("tablesFolder: " + tablesFolder);
session.Log("functionsFolder: " + functionsFolder);
session.Log("spFolder: " + spFolder);

In my log file I see
ExecuteSQLScripts BEGIN
tablesFolder: C:\Users\ADMINI~1\AppData\Local\Temp\Tables\
functionsFolder: C:\Users\ADMINI~1\AppData\Local\Temp\Functions\
spFolder: C:\Users\ADMINI~1\AppData\Local\Temp\Stored Procedures\
These files do not exist at any time before, during or after the installation process (I am assuming the truncated path is actually C:\Users\Administrator\).
tmwoods
Posts: 11
Joined: Thu Dec 19, 2019 10:32 pm

Re: Using Files and Folders during installation

OK, so I figured it out but want to post in case someone else stumbles across the same problem.

To use temporary files with a custom action, you can't just click 'Add Temporary Files' from the Files and Folders screen then use them. That will default them to be in the Windows Volume -> Windows -> Temporary. If you want them to be in the same directory as your Application, then you have to right-click in that area of Files and Folders and then add a temporary folder there. Then you can access it by it's identifier. If you try to use the identifier when it is in Windows Volume it doesn't work. Unless I'm misunderstanding something I would consider this to be a bug and a very irritating one.

Hope this helps for anyone who comes after me!
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Using Files and Folders during installation

Hi,

We are glad you got this sorted out.

Thank you for sharing with us your solution. Certainly this will be useful to future customers facing the same scenario.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”