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

The "RunCmd" Command

This MAKEMSI command will execute any command line which can be executed on a Windows command prompt and can examines its return code to determine if it succeeded or not.

This command supports the definition of lines of text between this command and any terminating "/RunCmd". The meaning of the lines depends on the "@" parameter's value.

This command takes these parameters:

RUNCMD Options/Defaults

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

#define? DEFAULT_RUNCMD_COMMAND
#define? DEFAULT_RUNCMD_KEEPINDENT      Y
#define? DEFAULT_RUNCMD_NEXTID          Y          ;;"@@" etc will be converted
#define? RUNCMD_CAD_SYMBOL_START        (*         ;;(*CadSymbolName*)
#define? RUNCMD_CAD_SYMBOL_END          *)         ;;(*CadSymbolName*)
#define? RUNCMD_FROM_SOURCE_FILE \
         <$SourceFile FileName="{$FileName}" Html="Y"> ;;Add to HTML report
#define? RUNCMD_SEQUENCE_NUMBER         DuplicateFiles-InstallFinalize

EXAMPLE - RUNCMD via SQL Aliases

The following example uses the "OSQL.EXE" which is expected to be available on the installed system. Note that "OSQL.EXE" uses the "-i" option to specify the name of an input file.

;--- Use existing ".SQL" file -----------------------------------------------
<$Sql file="Update.SQL" Command=^"osql.exe" -E -b -n -w512 -S . -d "DatabaseName" -i "{?}"^>

;--- .SQL inline ------------------------------------------------------------
#define MySqlCmd  osql.exe -E -b -n -w512 -S . -d "DatabaseName" -i "{?}"
<$Sql Command=^<$MySqlCmd>^>
   Delete from
       INF_Router
   Where
       ID_Process = 18 and ProcessName = 'GetAllDBUsers'
   GO

   Delete from
       INF_Error
   Where
       ID_Source = 'Operator.GetXMLForAllDBOperators'
   GO
<$/Sql>
<$Sql Command=^<$MySqlCmd>^>
      #include "SqlPart1.SQL"
      #include "SqlPart2.SQL"
<$/Sql>

This example uses "MySql" an gets the database name from a Windows Installer property:

#data "CaSqlData"
      "Database" "[DBNAME]"     ;;DBNAME comes from dialog (or command line if silent)
#data

#define MySqlCmd "mysql.exe" --user=root --password=PASSWORD1 < "{?}"
<$Sql Command=^<$MySqlCmd>^ DATA=^CaSqlData^>
      CREATE DATABASE IF NOT EXISTS (*Database*);
<$/Sql>

#define MySqlCmd2 "mysql.exe" --user=root --password=PASSWORD1 < "{?}"
<$Sql Command=^<$MySqlCmd2>^ DATA=^CaSqlData^>
    USE (*Database*);
    #include "query.sql"
<$/Sql>

Example - Use CACLS.EXE

The following example shows how some macros could be used to set up some comamnds which invoke "cacls.exe" to set or modify ACLs:

;--- Handy commands you may wish to use -------------------------------------
#define  CACLS   <$RunCmd  {$?} ALIAS="CACLS" Command="CACLS.EXE" @="N">    ;;"CACLS.EXE" installed with WIN2000 & WINXP (at least on PRO)
#define  /CACLS  <$/RunCmd {$?} ALIAS="/CACLS">

;--- Update ACL on "fred.ini" -----------------------------------------------
<$CACLS CONDITION=^<$CONDITION_INSTALL_ONLY>^>
    ;--- Name of file we wish to modify ACL on ------------------------------
    "%WinDir%\system32\fred.ini"

    ;--- Edit ACL instead of replacing it -----------------------------------
    /E

    ;--- Deny administrators access -----------------------------------------
    /D administrators
<$/CACLS>

The example below makes use of the same macros used above but shows a how you can reference the installation directory (or msi properties in general):

#data '@@INSTALLDIR' 2
    ;--- Install time name and location of SETACL tool ----------------------
    "INSTALLDIR" "[INSTALLDIR]"
#data
<$CACLS CONDITION=^<$CONDITION_INSTALL_ONLY>^ DATA="@@INSTALLDIR">
   "(*INSTALLDIR*)SomeFile.txt"
   /E
   /G Users:C
<$/CACLS>

You could use the "ExeCa" command to execute the program without a script (which you may wish to do) however these are some of the disadvantages:

  1. You will have reduced (almost no) logging.
  2. Better error messages presented to user, giving you a much better chance of quickly resolving any problems.
  3. More limitations on return code handling.


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]: RowsDeleteAll[Next]: /RunCmd


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.