PDA

View Full Version : MsiGetTargetPath problem



Pizzamampf
09-25-2018, 11:33 AM
Hi, I'm quite new with InstallShield and currently working on my first project (using InstallShield 2018 Professional), so I'm running into lots of trouble. Currently I'm stuck with MsiGetTargetPath and even searching this forum couldn't find any solution.

Quick problem setup:
I have a Basic MSI project. In Properties I've defined a property called "MAINDIR". The value is looked up from registry: In RegLocator I read a value into regSignatureMaindir, in AppSearch I connect it to the MAINDIR property. Generally, looking up the Property results in the correct path, so this part works as expected.
In Directory view, directories are defined as follows (besides several other standard directories):


Directory Directory_Parent DefaultDir
-----------------------------------------
MAINDIR TARGETDIR MAINDIR
TOOLSDIR MAINDIR tools

The "Target Directory Path" preview shows [MAINDIR] for the first entry and [MAINDIR]\tools for the second. Looks alright to me.

In my InstallScript Custom Action I try this:


nvSize = MAX_PATH + 1;
MsiGetTargetPath(hMSI, "TOOLSDIR", svToolsdir, nvSize);
SprintfMsiLog("Tools dir is %s.", svToolsdir);

Unfortunately, svToolsdir is always empty. Just for a test, I also tried to look up MAINDIR instead, same result: MsiGetTargetPath returns an empty string.

In other Custom Actions, for example type "Launch an executable", I can use TOOLSDIR as working directory and also reference [TOOLSDIR] in "File Name & Command Line", it works perfectly. Generally it seems the properties are set up correctly.
Is there anything I missed, any property I'd have to set for MsiGetTargetPath?


Edit:
Just some more information: Within the same InstallScript method I also can't look up the properties using MsiGetProperty; I get an empty result.
In "Custom Actions and Sequences" view the custom action is set as "Synchronous (Check exit code)" and execution "Deferred Execution in System Context". Install Exec Sequence: After WriteIniValues. Just in case it matters.

MarkusLatz
09-25-2018, 12:03 PM
If your custom action is executed in "Deferred Execution in System Context", then you should read this:

Obtaining Context Information for Deferred Execution Custom Actions (http://helpnet.flexerasoftware.com/installshield24helplib/installshield24helplib.htm#helplibrary/AccessingProps-DeferredCAs.htm?Highlight=customactiondata)

regards

Markus

DanGalender
09-26-2018, 10:19 AM
If your custom action is executed in "Deferred Execution in System Context", then you should read this:

Obtaining Context Information for Deferred Execution Custom Actions (http://helpnet.flexerasoftware.com/installshield24helplib/installshield24helplib.htm#helplibrary/AccessingProps-DeferredCAs.htm?Highlight=customactiondata)

regards

Markus

I agree with Markus if your action needs to be a run in deferred mode. If you are trying to get the value of a property, which a directory identifier is, I would think that it could (and should) be done in immediate mode, thereby eliminating the need to deal with CustomActionData. If you make this change, schedule that action to run after CostFinalize and before InstallInitialize.

Pizzamampf
09-26-2018, 11:09 AM
Thanks very much to both of you!
The hint from Markus brought the solution. I need the deferred action because after getting the property, some changes will be made to the system and according to the documentation, those cases should always be deferred actions.
Now just fighting with support files, but that might be another story another time...