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]: IniImport[Next]: /JsCa
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
\->Source Code->Commands->JsCa

The "JsCa" Command

This command is used to start the definition (and creation) of a Windows Installer JSCRIPT (javascript) based custom action which ends when the /JsCa command is encountered. The generated script is automatically added into the "Binary" table. You should be aware of the "Norton's Malicious Script Detection" issue.

If you have an existing Windows Scripting Host (WSH) script which you want to use, use the "ExeCa" command to invoke "WSCRIPT.EXE". All parameters will typically be passed on the command line and no logging will take, in my mind good reasons why this should be avoided at nearly all costs.

You will indicate the function entry points (which you will schedule via the JsCaSetup command) with the JsCaEntry and /JsCaEntry commands. You place your code between these two commands. You may define contants and common initialization code above the first use of "JsCaEntry".

I highly recommend the use of the CaDebug function and will be reluctant to look at any user supplied code which doesn't make use of it to indicate progress and to make the code easier to debug when it fails.

If imbedding within a macro please ensure that the "current" line continuation is "<?NewLine>".

The generated script has these main characteristics:

Microsoft actually have some very useful script information and samples at "http://www.microsoft.com/technet/scriptcenter/default.mspx". I have a collection of other useful scripting links at "http://dennisbareis.com/bookmark_developer_windows_scripting_host.htm".

Parameters

This command takes these parameters:

Main "JsCa" Options

Please see the "options for commands" section of the manual.

;----------------------------------------------------------------------------
;--- General Options --------------------------------------------------------
;----------------------------------------------------------------------------
#define? DEFAULT_JSCA_CAD_DELIMITER           ,_,              ;;Must be 1-9 characters long
#define? JSCA_LOGDIR_ENVVAR                   MAKEMSI_LOGDIR
#define? JSCA_LOG_OK_ENVVAR                   MAKEMSI_LOG      ;;Set this environment variable to N to disable logging
#define? JSCA_LOGDIR_EXP_4_DEFAULT            "C:\\"           ;;By default place in C:\ (can be any JSCRIPT expression)
#define? JSCA_LOGFILE_BASENAME_PREFIX         MAKEMSI_JSCA-
#define? DEFAULT_JSCA_SEQTABLE                InstallExecuteSequence
#define? JSCA_INC_BY_SPACE_COUNT              4
#define? JSCA_ROW_@VALIDATE                   NEW                         ;;See the "@Validate" parameter of the "ROW" command
#define? JSCA_ROW_@VALIDATE_INLINE            NEW -Target:STRINGOVERFLOW  ;;See the "@Validate" parameter of the "ROW" command (lets allow the script to exceed the columns 255 character width)
#define? JSCA_PAUSE                           <$SUNDRY_CA_PAUSE> ;;Debug pauses (Y/N)
#define? JSCA_DISABLED                        <$SUNDRY_DISALLOW_USE_OF_SCRIPT_CUSTOM_ACTIONS> ;;Make non blank to disable (text is error message)
#define? JSCA_DEFAULT_TYPE_ATTRIBUTES
#define? JSCA_DEFAULT_TYPE_ATTRIBUTES_INLINE  immediate           ;;For inline (in CA table) based CA
#define? JSCA_BINARY_DOCO                     Y                   ;;"N" = Don't add to doco
#define? JSCA_BINARY_COMMENT                  This file generated by the "JsCa" command at <??RxMmLocation>

;----------------------------------------------------------------------------
;--- Custom Action conditions -----------------------------------------------
;----------------------------------------------------------------------------
#define? JSCA_CONDITION_INSTALL_ONLY    <$CONDITION_INSTALL_ONLY>
#define? JSCA_CONDITION_UNINSTALL_ONLY  <$CONDITION_UNINSTALL_ONLY>

EXAMPLE - Very Simple INLINE Custom Action to Remove Trailing Backslash

<$JsCa Binary="!SimpleJS">
     var InstallDir = Session.Property("INSTALLDIR");
     InstallDir = InstallDir.slice(0, -1);              ;;Remove last character (\) from the path
     Session.Property("DIR_NO_SLASH") = InstallDir      ;;You will see this action logged in any verbose log
<$/JsCa>
<$JsCaSetup Binary="!SimpleJS" Seq="CostFinalize-" SeqTable="InstallExecuteSequence" CONDITION=^<$CONDITION_INSTALL_ONLY>^>

See the "Remove Trailing Slashes from Directory Names" tip for some other languages.

EXAMPLE

;--- Create a JSCRIPT and add to the binary table ---------------------------
<$JsCa Binary="SimpleCa.js">
    var some = 1

    <$JsCaEntry "Install">
    {
        try
        {
            CaMsgBox("E", "test of the error box")
        }
        catch(e)
        {
            CaDebug(0, "Install_1 function: trapped")
        }
    }
    <$/JsCaEntry>

    <$JsCaEntry "UnInstall">
        UserFunction("Uninstalling...")
    <$/JsCaEntry>

   //==========================
   function UserFunction(Text)
   //==========================
   {
       CaDebug(0, "Doing something...")
       CaMsgBox("I", Text)
       CaDebug(0, "Finished doing something...")
   }
<$/JsCa>

;--- Call the above script during install and uninstall ---------------------
<$JsCaSetup Binary="SimpleCa.js" Entry="Install"    Deferred=Y Seq="InstallFiles-" CONDITION=^<$CONDITION_INSTALL_ONLY>^>
<$JsCaSetup Binary="SimpleCa.js" Entry="UnInstall"  Deferred=Y Seq="InstallFiles-" CONDITION=^<$CONDITION_UNINSTALL_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]: IniImport[Next]: /JsCa


MAKEMSI© is (C)opyright Dennis Bareis 2003-2008 (All rights reserved).
Friday October 13 2017 at 2:08pm
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.