MAKEMSI quickly and reliably creates MSI files in a non-programmatic way
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
[Bottom][Contents][Prev]: Deferred Custom Actions[Next]: Immediate Custom Actions
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
\->Windows Installer FAQ (the basics)->Custom Actions->Types of Custom Actions->Deferred Custom Actions->CustomActionData

CustomActionData

Most property values are not available to deferred custom actions and for this reason Windows Installer defines the "CustomActionData" property as a mechanism for passing data to the task.

If you have more than one parameter to pass you will need to pick a character which will never appear in any of the parameters and combine all the parameters into a single string (using the chosen character as a delimiter). The custom action will know the character and will split up the string back into its component parameters.

As the value would normally include some MSI formatting (otherwise you would simply use a PPWIZARD "#define" to pass/code the information) you would normally use the "PropertyCa" command to set up the custom action data.

MAKEMSI includes some inbuilt support for custom action data, see the "DATA" parameter of the "VbsCaSetup" command and the "VbsCaCadGet" function.

EXAMPLE - Using inbuilt support

MAKEMSI commands refer to the custom action data with the DATA parameter as demonstrated here:

;--- Set up the 2 parameters (CustomActionData) -----------------------------
#data "Fred"
   "Name1" 'Name 1 Value'          ;;Parameter 1 (name + value)
   "Name2" "[INSTALLDIR]"          ;;Parameter 2
#data

;--- Deferred Custom Action which accesses 2 passed parameters --------------
<$VbsCa Binary="TestCustomActionDataPassing.vbs" DATA="Fred">
   <$VbsCaEntry "Install">
       ;--- Do something ----------------------------------------------------
       Show("Install: NAME1=" & VbsCaCadGet("Name1"))
       Show("Install: NAME2=" & VbsCaCadGet("Name2"))
   <$/VbsCaEntry>

   '=======================
   sub Show(Text)
   '=======================
       CaMsgBox "I", Text
   end sub
<$/VbsCa>

;--- Set up the Deferred custom action passing the CustomActionData ---------
<$VbsCaSetup Data="Fred" Binary="TestCustomActionDataPassing.vbs" Entry="Install" Seq="InstallFiles-" CONDITION=^<$CONDITION_INSTALL_ONLY>^>

EXAMPLE - Not Using inbuilt support

This code shows how 3 parameters are passed to the simple deferred custom action.

;--- Create the custom action script ----------------------------------------
<$VbsCa Binary="Test.vbs">
   ;--- Initialization (get passed arguments) -------------------------------
   #define NUM_ARGS_EXPECTED 3
   public args, CaData
   CaData = VbsCaPropertyGet("CustomActionData", "c:\tmp;2;3", "Must be 3 semi-colon separated values!")
   args   = split(CaData, ";")
   if  ubound(args)+1 <> <$NUM_ARGS_EXPECTED> then
       VbsCaRaiseError "Argument Validation", "Got " & ubound(args)+1 & " arguments, we expected <$NUM_ARGS_EXPECTED>!"
   end if

   ;--- Install code --------------------------------------------------------
   <$VbsCaEntry "Install">
       DisplayArgs "Install"
   <$/VbsCaEntry>

   ;--- Uninstall code ------------------------------------------------------
   <$VbsCaEntry "UnInstall">
       DisplayArgs "UNInstall"
   <$/VbsCaEntry>

   ;--- common user function ------------------------------------------------
   sub DisplayArgs(When)
       CaMsgBox "I", "WHEN=" & When & vbCRLF & "1=" & args(0) & vbCRLF & "2=" & args(1) & vbCRLF & "3=" & args(2)
   end sub
<$/VbsCa>

;--- The 3 parameters we wish to pass ---------------------------------------
#( ';'                      ;;Use semicolon to delimit the parameters (data must not contain it!)
   #define TEST_ARGS

   [%USERNAME]         ;;Try environment variable
   [INSTALLDIR]        ;;Try "Directory" key/property
   [#ppwizard.rex]     ;;Try full name of file as installed
#)

;--- Create the property and setup the custom action ------------------------
<$PropertyCa     "TEST_Install" Seq="InstallFiles-" Value="<$TEST_ARGS>">
<$VbsCaSetup Key="TEST_Install" Seq="InstallFiles-" Binary="Test.vbs" Entry="Install" CONDITION=^<$CONDITION_INSTALL_ONLY>^>


Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.Please email me any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Prev]: Deferred Custom Actions[Next]: Immediate Custom Actions


MAKEMSI© is (C)opyright Dennis Bareis 2003-2008 (All rights reserved).
Saturday May 28 2022 at 3:11pm
Visit MAKEMSI's Home Page
Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.