Getting SourceDir property from c # custom action

I have several directories that are linked to my installer and I need to access them from a custom action. I did some research and saw that SourceDir can be used to get the current executable directory. However, I cannot find examples of how to get this property? Or another way to get the current directory?

Can anyone advise or point me to something other than Microsoft's useless site?

+1


source to share


3 answers


I am assuming you are using vbscript for custom actions. If so, the properties can be accessed through the Session object. See below:

strSourceDir = Session.Property("SourceDir")

      



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

+1


source


In C #, you will 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 understanding.



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 the ResolveSource action is called, which can only be called after CostInitialize has started.

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

+1


source


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

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

      

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

0


source







All Articles