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

Set a Directory Table Entry at Run Time

Set a Directory Table Entry at Run Time

Summary

This article describes how to create a Directory table entry and set it through InstallScript in an MSI Project.

Synopsis

This article describes how to create a Directory table entry and set it through InstallScript in an MSI Project.


Discussion

The following steps can be used to create a Directory table entry, and set it to a desired path via InstallScript.

  1. Open the Directory Table via the Direct Editor.

  2. Create the following row in the Directory table:

    DirectoryDirectory_ParentDefaultDirIsDescriptionIsAttributes
    MYDIRTARGETDIR.

  3. Navigate to the InstallScript view and create a new script file.

  4. On the right side, you will fine a default function called MyFunction. Modify the function so that it looks like the following:
    function MyFunction(hMSI)
    STRING svString;
    
    begin
      svString = "C:\\TestFolder";
      //Two slashes are needed in order to define subdirectories in InstallScript.
      //Note: for the purposes of this script, the path has been hardcoded.
      //You must have an accessible C drive to run this script.
      //If you do not have a C drive then change the path to point to an accessible drive.
      MsiSetTargetPath(hMSI, "MYDIR", svString);
    end;

  5. Compile the script.

  6. Right-click Custom Actions in the Sequences/Action view.

  7. Select Custom Action Wizard from the context menu.

  8. Proceed through the wizard, and give the custom action a unique name.

  9. Select Run InstallScript code for the custom action type, and in the next panel, select MyFunction (or the new name of the entry-point function) for the source.

  10. Select Next, accepting the default selections until the wizard creates the custom action.

  11. Right-click the CostFinalize action in the User Interface or Execute sequence, and choose Insert.

  12. Select Custom Actions from the drop-down box provided, and choose your custom action.

  13. Put a condition of Not Installed on the custom action.

  14. Build a release and run the setup.

Additional Information

For more information on the functions discussed, see the Windows Installer Help Library topics MsiSetTargetPath and CostFinalize.

Was this article helpful? Yes No
No ratings
Version history
Last update:
‎Oct 17, 2007 07:49 PM
Updated by: