cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
jharveyjr
Level 3

MsiGetProperty inconsistencies

I am using an InstallScript MSI and am having problems getting property values from MsiGetProperty inside my InstallScript. Is there some reason that would explain it because it makes no sense to me.

nvBufferSize = MAX_PATH;
MsiGetProperty(ISMSI_HANDLE, "SUPPORTDIR", svSupportDir, nvBufferSize);

Those lines in a function called by a custom action work. However, those same lines inside of a function called from FirstUIAfter doesn't return any thing. However, the INSTALLDIR property has a value in FirstUIAfter.

I have seen this happen with other values too. And my biggest frustration is that there doesn't seem to be any rhyme or reason to it.

What am I missing?
Labels (1)
0 Kudos
(2) Replies
joshstechnij
Level 10 Flexeran
Level 10 Flexeran

MSI properties set during the pre-file transfer events (OnBegin, OnFirstUIBefore, etc.) or set during immediate custom actions will lose their values in post-file transfer events (OnFirstUIAfter, OnEnd, etc.). This is an unintended side-effect due to how InstallScript MSI projects are implemented.

The basic reason for this is the InstallScript engine acts as an external UI handler for the MSI package being installed. In order to interact with Windows Installer, the InstallScript engine opens an installation session through the MsiOpenPackage API. All properties set during pre-file transfer events are backed by this installer session. Just before file-transfer is started, this installer session needs to be closed, otherwise, Windows Installer would be unable to read the MSI package and the install would fail. A consequence of closing the session is any properties set during that session are essentially lost. Properties that are Directory table entries, such as INSTALLDIR, are reinitialized after file-transfer by running the Windows Installer costing actions.

If you need to maintain property values between pre and post file transfer events in InstallScript, global variables should be used in addition to or instead of MSI properties. Properties set during custom actions in the execute sequence would need to be written to a file or registry entries on the machine as there is no way to pass global variables from InstallScript custom actions to InstallScript events.
0 Kudos
jharveyjr
Level 3

Thank you! This is very informative.
0 Kudos