views:

1623

answers:

4

I have some directories that are bundled with my installer and I need to access them from within a custom action. I have done some research and seen that the SourceDir can be used to obtain the currently executing dir location. However I cannot find any examples of how to obtain this property? Or another way to obtain the current directory?

Can anyone advise or point me to anything other than the unhelpful Microsoft site?

+1  A: 

I'm assuming you're using vbscript for the custom action. If so, properties can be accessed via the Session object. See below:

strSourceDir = Session.Property("SourceDir")

Be aware that the SourceDir property is only available at specific times during the installation.

w4g3n3r
A: 

For C#, you'll find that you can do something like this:

[CustomAction]
public static ActionResult MyCustomAction(Session session)
{
    string sourceDir = session["SourceDir"];
    string path = Path.Combine(sourceDir, "yourfilename.txt");
    ...

The documentation on MSDN is unfortunately lacking in making this clear.

As w4g3n3r mentions in his answer, SourceDir is only available to you at certain times. In short, you will need to make sure your custom action is called after a call to the ResolveSource action, which can only be called after CostInitialize has run.

Once SourceDir is set, it should be available for use for the remainder of the installation process.

Chris
A: 

Are you using InstallShield? Here's an example for an InstallScript CA:

MsiGetProperty(hMSI, "CustomActionData", strDirectory, numBuffer);

... where you also used a Set Property "Type 51" custom action to setup CustomActionData for your function to the value SOURCEDIR.

William Leara
A: 

I came here looking for the solution of the same problem and was finally able to fetch the source directory of my setUp.exe. It is simply using the SOURCEDIR variable in customActionData. I have written about the problem i faced and its solution on this forum.

Hope it will help other people also.

Anil