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

  How to access INSTALLDIR property with PowerShell and VBS CustomAction

  How to access INSTALLDIR property with PowerShell and VBS CustomAction

Summary:

    How to access INSTALLDIR property with PowerShell and VBS CustomAction

 

Symptoms:

 

This article explains how to use a powershell and Vbs custom action to access an INSTALLDIR property using custom action. This information applies to the following InstallShield project types:

  • Basic MSI
  • InstallScript MSI 

 

Solution:

For Powershell CustomAction
  1. Create Basic MSI Project
  2. Go to CustomAction view
  3. Add a set property CustomAction and rename it "SetPropertyCA"
  4. Property Name SETCUSTOMINSTALLDIR and value set to [INSTALLDIR]
  5. Set InstallExec to After AppSearchSetpropertyCA.PNG
  6. Create a Powershell Customaction with stored in Binary table
  7. Browse and add the .ps1 file (save below code as Test.ps1)
  8. Powershell Script.PNG
  9. $Path = get-property -name SETCUSTOMINSTALLDIR

    $wshell = New-Object -ComObject Wscript.Shell
    New-Item $Path -ItemType "Directory"
    $a = new-object -comobject wscript.shell
    $b = $a.popup("INSTALLDIR: $Path",0,"Test Message Box",1)
    #[System.Windows.MessageBox]::Show('Would you like to Install the Setup?','Setup input','YesNoCancel','Error')
    #$msgBoxInput = [System.Windows.MessageBox]::Show($Path,'Game input','YesNoCancel','Error')
    Start-Process -FilePath $Path\Notepad2.exe

  10. Set InstallExec to After SetPropertyCA
  11. Save the project 
  12. Build and Run the project.

  Vbs CustomAction:

  1. Create Basic MSI Project
  2. Go to CustomAction view
  3. Add a  Vbs Custom Action with stored in binary table option
  4.  Browse and add your .vbs file (save below vbs file as installdir.vbs)
  5. Function InstallDIRTest()
    Dim INSTALLDIR, SRCDIR

    ' first, path to the msi file
    INSTALLDIR = Session.Property("INSTALLDIR")

    'MsgBox Session.Property("INSTALLDIR")

    MsgBox "The value of INSTALLDIR is now " & session.Property("INSTALLDIR")

    End Function ' InstallMySQL

  6. Set InstallExec to After InstallInitialize vbs Script.PNG
  7. Set "use 64 bit scripting" option to YES.
  8. Save the project 
  9. Build and Run the project.

Reference:

KB article to access MSI property with a deferred custom action  

Installshield help document for INSTALLDIR Property in a VBScript Custom Action 

No ratings
Version history
Last update:
‎Feb 01, 2023 11:46 PM
Updated by:
Contributors