cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Pizzamampf
Level 4

MsiGetTargetPath problem

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.
Labels (1)
0 Kudos
(3) Replies
MarkusLatz
Level 8

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

regards

Markus
0 Kudos
Dan_Galender
Level 10

MarkusLatz wrote:
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

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.
0 Kudos
Pizzamampf
Level 4

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...
0 Kudos