installationwindows-installerinstallshieldinstallscriptinstallscript-msi

Get dir setup install shield


I want get dir my setup create by install shield. I use command parametter Setup.exe /path=[SETUPEXEDIR]\log.txt My setup location is Desktop\myapp\Setup.exe When use [SETUPEXEDIR] return temp folder I want when use [SETUPEXEDIR] return me my Setup.exe location.

I use installshield 2016 version 23 SP 2. I use MSI Script.

I want get location and use in command parameter prerequisites.


Solution

  • A little hard to comprehend exactly what you are asking, but as far as I understand you want to know the location where setup.exe is running from?

    Variables

    A word to the wise: if you are indeed using Installscript MSI you should know that it is a very buggy type of project, and you should seriously consider switching to Basic MSI to save yourself grief. I can provide more information on this if you like. I had to abandon Installscript MSI entirely to make my deployment problems go away.

    Installshield Properties

    It seems different versions of Installshield may behave differently and feature varying support for these folder properties / variables. It also seems the properties may not work with all types of release media. And finally they may only work in Basic MSI or Installscript MSI respectively. The properties I have found are: PACKAGE_LOCATION, SETUPEXEDIR and SRCDIR. There also appears to be an Installscript method called GetCurrentDir() available in recent versions of Installshield, but the documentation warns about using it (see link).

    Please visit the links above in sequence and read in detail about each property's (or method's) limitations. It is very important that you use the option (if any) that matches your requirements and scenario. For example PACKAGE_LOCATION works only for Installscript MSIs, SETUPEXEDIR is set by Setup.exe. If the end user runs the .msi package directly, SETUPEXEDIR is not set.

    MSI Built-in Property

    It seems to me that getting the built-in MSI property SourceDir might be an option to try. My quick test indicates that it works for both InstallScript and Basic MSI. However, I do not know if this works for all versions of Windows Installer. Please test on various Windows versions to be sure.

    You should also be aware of the potential problem using SourceDir which is described in the documentation for SETUPEXEDIR. This goes for setups that are compiled into a single, compressed setup.exe containing all files - this launcher will extract the MSI file to a temp location and run from there. When I tried with an uncompressed network image it worked fine to use SourceDir.

    Finally, if you use a setup.exe to compress all files and enable the caching of the MSI on the system, then you will be running from somewhere inside: C:\WINDOWS\Downloaded Installations\{GUID}\.

    All of this could be different on newer versions of Installshield. I am testing with an ancient version I have available. Please test thoroughly on your version.

    I should also mention the OriginalDatabase built-in MSI property. Check the link for documentation on how it will be set.

    Some links:

    Installscript Function For Testing

    And just for reference, here is a quick and dirty function to test these properties from an Installshield custom action (this is for other people who may find this without having tested as much as you):

    function TestFolderProperties(hMSI)   
         STRING svName;
         NUMBER nvSize;
    begin             
    
        // MSI properties
        nvSize = 256;
        MsiGetProperty (hMSI, "SETUPEXEDIR", svName, nvSize);
        MessageBox ("SETUPEXEDIR: " + svName, INFORMATION);
        MsiGetProperty (hMSI, "SourceDir", svName, nvSize);
        MessageBox ("SourceDir: " + svName, INFORMATION);
        MsiGetProperty (hMSI, "OriginalDatabase", svName, nvSize);
        MessageBox ("OriginalDatabase: " + svName, INFORMATION);
    
        // System Variables
        MessageBox ("SRCDIR: " + SRCDIR, INFORMATION);
        // PACKAGE_LOCATION is not available in my version of Installshield, enable and test 
        //MessageBox ("PACKAGE_LOCATION: " + PACKAGE_LOCATION, INFORMATION);
    end;
    

    Remember to add the export to the top of the setup.rul file:

    export prototype TestFolderProperties(HWND);  
    

    Test compile to verify, and then create an Installscript custom action and put it in a sequence. Make "Return Processing" Synchronous (Ignores exit code) for the custom action. I put it right before InstallFinalize in the sequence, using immediate mode execution. Rebuild your release and run it. Try different release build configurations (msi with external source files, MSI only with compressed files inside, setup.exe launcher with external files, setup.exe with all files compressed inside, setup.exe with caching, setup.exe without caching, etc... the behavior might be different).