MSI Builder (Custom Action) Get Source Directory (MSI Path location)

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 1 year and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Christoffer
Posts: 2
Last visit: Wed Dec 20, 2023 10:55 am

MSI Builder (Custom Action) Get Source Directory (MSI Path location)

Post by Christoffer »

I would like to see another option on customactions, specifically sourcedirectory of the MSI itself.
It is retrievable according to Microsoft documentation (Sourcedir).
The SourceDir property is the root directory that contains the source cabinet file or the source file tree of the installation package. This value is used for directory resolution.
The ResolveSource action must be called before using the SourceDir property in any expression or attempting to retrieve the value of SourceDir with MsiGetProperty. The ResolveSource action should not be run while the source is unavailable, such as when uninstalling an application, because this can cause an unintended prompt for the source media.
In some projects, i am making it would be great to be able to load a file for example a logo or settings file, from the path as the msi is running from.
I have found an "ugly" way to accomplish this (reading from the eventlog, and substring away the "installer.msi"), but if it was built in, it would fail the install if the file was not present. I have tried some myself, but im not sure how i can retrieve the Sourcedir from MsiGetProperty.

Ugly "solution" that i run from installdir, after install:

Code: Select all

$r = get-winevent -FilterHashtable @{ Logname = "Application"; ID = 1040 } -MaxEvents 1
[xml]$evt = $r.ToXml()
$installfromlocation = $evt.Event.EventData.Data[0]
$installfromlocation = $installfromlocation.Substring(0, $installfromlocation.lastIndexOf('\'))
$settings = "$installfromlocation\Configure\Settings.config"
$logo = "$installfromlocation\Configure\Logo.png"
Microsoft description of the property:
I am not allowed to link yet, but a google search on "SourceDir property" first hit is Microsoft.
User avatar
Alexander Riedel
Posts: 8472
Last visit: Mon Mar 18, 2024 2:59 pm
Answers: 19
Been upvoted: 37 times

Re: MSI Builder (Custom Action) Get Source Directory (MSI Path location)

Post by Alexander Riedel »

The Wix Toolset executes custom actions externally, outside of the context of the MSI. So it really has no access to internal properties once it is running.
I have not tried this yet, but maybe you can just pass the property as a parameter to your custom action.
Theoretically, if you pass [SourceDir] as a parameter, it should resolve to the proper value when your script is called.
Alexander Riedel
SAPIEN Technologies, Inc.
Christoffer
Posts: 2
Last visit: Wed Dec 20, 2023 10:55 am

Re: MSI Builder (Custom Action) Get Source Directory (MSI Path location)

Post by Christoffer »

Thank you for your suggestions, i have not been able to get it to work, but i do it "my ugly way" and use a custom exe as a installhelper (that also remove the files not in the msi, that would have been left), that return other then 0 (1) if the files are missing and show a messagebox, so it accomplish the same (and the installer fails, if files are not present), but in a not so convenient way.
I have played arround trying to get the property (originalDatabase and SourceDir) in numerous different ways, but i cannot get it to work. The only drawback is that the installer has to write the files to Programfiles folder, so custom action needs to run as system to be able to copy the files, and if running from a share, the domain computer needs permissions to the share/folder. "It works" for my need, just have to communicate the procedure properly.
I tried myself with wix to see how other people are doing it, but it seems very hard to accomplish if you are not a "programmer" by profession, to be able to grab the Msigetproperties during session.

Thank you anyway, if i get more time i will try some more, i could probaby be able to make it in advanced installer, but thats not a free feature, and for personal use/free applications i am making, i am not interested in paying that amount of money just for this to be "nicer".
User avatar
Alexander Riedel
Posts: 8472
Last visit: Mon Mar 18, 2024 2:59 pm
Answers: 19
Been upvoted: 37 times

Re: MSI Builder (Custom Action) Get Source Directory (MSI Path location)

Post by Alexander Riedel »

I will see what I can find out after the holiday weekend.
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 1 year and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.