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]: Don't ignore or completely turn off Validation Messages[Next]: Tips and Tricks
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
\->Best Practices->Create and Use Macros!

BEST PRACTICE: Create and Use Macros!

Create and Use Macros!

There is nothing "magic" about MAKEMSI's commands they are all simply PPWIZARD programming, it is recommended that you create your own macros for "bits" of code you find you are using all the time. You would add these to your common header file which you automatically "#include" at the start of your script.

There are many advantages to doing this including making it easier to write scripts which use common macros to represent possibly complex requirements. Your scripts are much more reliable as the macro has been "tested" (used) in many other scripts.

As well as the examples on this page you should also see:

  1. Create Macro For Adding Files
  2. FilesInUse Dialog - Display if Program Running
  3. No Installation Registration
  4. Printer Driver Installation
  5. Twin Dialogs

Example 1 - Create a "PropertyRemove" command

    ;--- Create the macro ---------------------------------------------------
    #(  ''
        #define PropertyRemove

        ;--- Validate parameters (against supplied list) --------------------
        {$!:#1}

        ;--- Do the work ----------------------------------------------------
        <$Table "Property">
            <$RowsDelete WHERE="`Property` = '{$#1}'">      ;;Won't fail if no match...
        <$/Table>
    #)

    ;--- Try it... ----------------------------------------------------------
    <$PropertyRemove "some_possibly_existing">

Example 2

The following creates a macro which can be used to set your applications registry options (as written will overwrite any existing):

#(
   ;--- Define macro so set application options in registry -----------------
   #define AppOption
   <$Registry
                HKEY="LOCAL_MACHINE"
                 Key="SOFTWARE\MyCompany\MyAppOptions"
                Name=`{$#1}`
               Value=`{$Value}`
             KeyPath="{$KeyPath='N'}"         ;;Optional parm (default = N)
       MsiFormatted="NAME,VALUE"
   >
#)

Example of the new macro being used:

<$Component "RegistryOptions" Create="Y" Directory_="INSTALLDIR">
   ;--- Component Keypath ---------------------------------------------------
   <$AppOption "Installed - By <$ProdInfo.ProductName> <$ProductVersion>" Value=^[Date] [Time]^ KeyPath="Y">

   ;--- Set many options ----------------------------------------------------
   <$AppOption "OptionA" Value=^a^>
   <$AppOption "OptionB" Value=^b^>
                ...
   <$AppOption "OptionZ" Value=^z^>
<$/Component>

Example 3 - File Command Variation

You can't get much simpler than this example:

#define FileRemoveFirst <$File {$?} REMOVE="Y">

It defines a new command which works just like the "file" command except that it forces the "REMOVE" option to "Y".

You should not also try to use the "remove" parameter with the macro as written, if you wanted to allow override the value (although as this commands name implies removal I'd also change its name) it could look more like:

#define FileRemoveByDefault <$File {$?} REMOVE="{$Remove=^Y^}">

The macro is used just like the file command:

<$FileRemoveFirst Source="TryMe.ver" Destination="[INSTALLDIR]\">


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]: Don't ignore or completely turn off Validation Messages[Next]: Tips and Tricks


MAKEMSI© is (C)opyright Dennis Bareis 2003-2008 (All rights reserved).
Sunday February 28 2016 at 3:45pm
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.