\
MAKEMSI Installs...
Samples Installed by MAKEMSI
Samples - Build New MSI/MSM
TryMeExcelAddIn.MM
This is one of the MAKEMSI samples which build a new MSI/MSM.
This MSI makes use of these "TryMe.MM" files:
- TryMe.ver
- TryMe.rtf
;----------------------------------------------------------------------------
; MODULE NAME: TryMeExcelAddIn.MM
;
; $Author: USER "Dennis" $
; $Revision: 1.0 $
; $Date: 30 Apr 2015 19:23:22 $
; $Logfile: D:/DBAREIS/Projects.PVCS/Win32/MakeMsi/TryMeExcelAddIn.MM.pvcs $
;
; DESCRIPTION
; ~~~~~~~~~~~
; Demonstrates:
; * Adding/removing an Excel add-in (most code in the "Excel-Add-In" command
; created here.
; * Runtime "version" of the "ProperyList" MAKEMSI command
; * Realistic use of the optional "FeatureIs" and "FeatureWillBe" macros to
; creation conditions for a feature being installed and uninstalled.
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
;--- Include MAKEMSI support (with my customisations and MSI branding) ------
;----------------------------------------------------------------------------
#define EXTN_DEFAULT_PROGID_PREFIX ;;I don't want a prefix so its easier to find in regedit (just need to type ".aa" or "aa")
#define VER_FILENAME.VER TryMe.Ver ;;I only want one VER file for all samples! (this line not actually required in "tryme.mm")
#include "ME.MMH"
;----------------------------------------------------------------------------
;--- Define default location where file should install ----------------------
;----------------------------------------------------------------------------
<$DirectoryTree Key="INSTALLDIR" Dir="c:\program files\TryMe (makemsi sample)\<$MAKEMSI_MM_BASENAME>" CHANGE="\" PrimaryFolder="Y">
;----------------------------------------------------------------------------
;--- Define some default values ---------------------------------------------
;----------------------------------------------------------------------------
#define? EXCEL_ADDIN_LIST_PROPERTY EXCELADDINS
#define? EXCEL_ADDIN_CONDITION_TO_INSTALL <$FeatureIs "<$Feature?>" STATE="ABSENT"> and <$FeatureWillBe "<$Feature?>" STATE="LOCAL">
#define? EXCEL_ADDIN_CONDITION_TO_UNINSTALL <$FeatureIs "<$Feature?>" STATE="LOCAL"> and <$FeatureWillBe "<$Feature?>" STATE="ABSENT">
;----------------------------------------------------------------------------
;--- Define the new "command" we will use below -----------------------------
;----------------------------------------------------------------------------
#RexxVar @@AddinCnt = 0 ;;Init count
#( '<?Newline>'
#define Excel-Add-In ;;Name the new command we are creating
;--------------------------------------------------------------------------
;--- Create a list of addins (";" delimitered), runtime "PropertyList" ---
;--------------------------------------------------------------------------
;<$PropertyList "<$EXCEL_ADDIN_LIST_PROPERTY>" VALUE="{$#1}">
#RexxVar @@AddinCnt + 1 ;;Inc Count (need diff binaries as text may/will differ)
#if [@@AddinCnt > 1]
;--- Add the delimiter between the values ---------------------------
<$PropertyCa "<$EXCEL_ADDIN_LIST_PROPERTY>" Value="[<$EXCEL_ADDIN_LIST_PROPERTY>];" Seq="InstallValidate-">
#endif
<$PropertyCa "<$EXCEL_ADDIN_LIST_PROPERTY>" Value="[<$EXCEL_ADDIN_LIST_PROPERTY>]{$#1}" Seq="InstallValidate-">
;------------------------------------------------------------------------
;--- Code to install and uninstall Excel add-ins ------------------------
;------------------------------------------------------------------------
#if [@@AddinCnt = 1]
;--- Only need to do this once --------------------------------------
<$VbsCa Binary="ExcelAddins.vbs">
<$VbsCaEntry "Add">
on error resume next
CaDebug 1, "Adding Excel add-ins"
AddOrRemove True
<$/VbsCaEntry>
<$VbsCaEntry "Remove">
on error resume next
CaDebug 1, "Removing Excel add-ins"
AddOrRemove false
<$/VbsCaEntry>
<?NewLine><?NewLine>
;============================================================================
sub AddOrRemove(Installing)
;============================================================================
;--- Initialization --------------------------------------------
on error resume next
dim PropertyList : PropertyList = "?" : PropertyList = session.property("<$EXCEL_ADDIN_LIST_PROPERTY>")
CaDebug 0, "List of ADD-INS: " & PropertyList
dim oFS : set oFS = CaMkObject("Scripting.FileSystemObject")
dim oXL : set oXL = CaMkObject("Excel.Application")
if Installing then
CaDebug 0, "INSTALLING ADD_INS: " & PropertyList
CaDebug 0, "Adding an empty workbook to Excel as a Excel bug/feature workaround..."
oXL.Workbooks.Add
else
CaDebug 2, "REMOVING ADD_INS: " & PropertyList
end if
;--- Process each request --------------------------------------
dim AddInNames : AddInNames = split(PropertyList, ";")
CaDebug 0, "There are " & ubound(AddInNames) + 1 & " add-ins to process"
CaDebug 0, ""
dim pi, oAddin
VbsCaLogInc 1
for pi = 0 to ubound(AddInNames)
;--- Get the name of the add-in -------------------------
err.clear()
dim AddInPath : AddInPath = AddInNames(pi)
CaDebug 2, "PROCESSING: " & AddInPath
;--- Process it -----------------------------------------
VbsCaLogInc 1
if Installing then
;--- Installing so verify the file exists -------
if not oFS.FileExists(AddInPath) then
CaDebug 0, "ERROR: Can't install the addin as the file is missing: " & AddInPath
else
CaDebug 0, "The file exists so we can go ahead and add it to excel"
err.clear()
set oAddin = oXL.AddIns.Add(AddInPath, false)
if err.number <> 0 then
dim Reason : Reason = hex(err.number) & " - " & err.description
err.clear()
CaDebug 0, "ERROR: oXL.AddIns.Add() failed, RC = 0x" & Reason
else
if oAddin.Installed then
CaDebug 0, "Add-in was already installed"
else
oAddin.Installed = True
CaDebug 0, "Add-in successfully added :-)"
end if
end if
end if
else
;--- Uninstalling -------------------------------
err.clear()
dim InstalledAddInCount : InstalledAddInCount = 0 : InstalledAddInCount = oXL.Addins.Count
dim ShortName : ShortName = oFs.GetFileName(AddInPath)
dim ii
CaDebug 0, "Looking through the " & InstalledAddInCount & " add-in slots for """ & AddInPath & """"
VbsCaLogInc 1
dim Found : Found = false
for ii = 1 to InstalledAddInCount
set oAddIn = oXL.Addins.item(ii)
dim AddInFN : AddInFN = "?" : AddInFN = oAddIn.FullName 'https://msdn.microsoft.com/EN-US/library/office/dn254066.aspx
err.clear()
dim State: State = "state unknown" : State = "Active/Installed = " & oAddIn.Installed
State = State & ", IsOpen = " & oAddIn.IsOpen 'IsOpen not supported on Excel 2003
err.clear()
CaDebug 0, "EXCEL ADDIN #" & ii & ": " & oAddIn.Name & " (" & State & "): """ & AddInFN & """"
if ucase(oAddIn.Name) = ucase(ShortName) then
VbsCaLogInc 1
Found = True
if not oAddIn.Installed then
CaDebug 0, "ALREADY REMOVED :-)"
else
oAddIn.Installed = False
CaDebug 0, "REMOVED IT :-)"
end if
VbsCaLogInc -1
end if
next
if not Found then CaDebug 0, "ADD-IN not found"
VbsCaLogInc 1
end if
VbsCaLogInc -1
next
VbsCaLogInc -1
;--- Cleanup ----------------------------------------------------
CaDebug 0, "Done, cleaning up..."
oXL.Quit
set oAddin = Nothing
set oXL = Nothing
set oFS = Nothing
end sub
<$/VbsCa>
<$VbsCaSetup Binary="ExcelAddins.vbs" Entry="Add" Type=^Immediate^ Seq="InstallFinalize-" SeqTable="InstallExecuteSequence" CONDITION=^<$EXCEL_ADDIN_CONDITION_TO_INSTALL>^>
<$VbsCaSetup Binary="ExcelAddins.vbs" Entry="Remove" Type=^Immediate^ Seq="InstallInitialize-" SeqTable="InstallExecuteSequence" CONDITION=^<$EXCEL_ADDIN_CONDITION_TO_UNINSTALL>^>
#endif
#)
;----------------------------------------------------------------------------
;--- These definitions are used by the above command ------------------------
;----------------------------------------------------------------------------
#ifndef FeatureIs ;;Defined elsewhere?
;--- Define Feature and Component state queries -------------------------
#define FeatureIs (!{$#1} <$INSTALLCOMPARE_{$IS=^EQUAL^}> <$INSTALLSTATE_{$STATE=^LOCAL^}>) ;;Feature is already installed
#define FeatureWillBe (&{$#1} <$INSTALLCOMPARE_{$IS=^EQUAL^}> <$INSTALLSTATE_{$STATE=^LOCAL^}>) ;;Feature is being installed
#define ComponentIs (?{$#1} <$INSTALLCOMPARE_{$IS=^EQUAL^}> <$INSTALLSTATE_{$STATE=^LOCAL^}>) ;;Component is already installed
#define ComponentWillBe (${$#1} <$INSTALLCOMPARE_{$IS=^EQUAL^}> <$INSTALLSTATE_{$STATE=^LOCAL^}>) ;;Component is being installed
;--- Define valid "IS" parameter comparison types -----------------------
#define INSTALLCOMPARE_EQUAL =
#define INSTALLCOMPARE_NOT_EQUAL <>
;--- Define valid "STATE" parameter values ------------------------------
#define INSTALLSTATE_UNKNOWN -1 ;;No action to be taken on the feature or component.
#define INSTALLSTATE_ADVERTISED 1 ;;Advertised feature. This state is not available for components.
#define INSTALLSTATE_ABSENT 2 ;;Feature or component is not present.
#define INSTALLSTATE_LOCAL 3 ;;Feature or component on the local computer.
#define INSTALLSTATE_SOURCE 4 ;;Feature or component run from the source.
#endif
;----------------------------------------------------------------------------
;--- Everything in its own feature ------------------------------------------
;----------------------------------------------------------------------------
<$Feature "ExcelAddIns" Title=^Excel Add-Ins^ Description=^Useful Excel Addins^>
<$Component "ExcelAddIns" Create="Y" Directory_="INSTALLDIR">
;------------------------------------------------------------------------
;--- Add the Excel ADD-IN files -----------------------------------------
;------------------------------------------------------------------------
<$File RowKey=^TryMeExcelAddIn.xla^ Source="TryMeExcelAddIn.xla" Comment="The add-in" KeyPath="Y">
;-----------------------------------------------------------------------
;--- Add the Excel ADD-INs to Excel (using the reusable code above) ---
;-----------------------------------------------------------------------
<$Excel-Add-In "[#TryMeExcelAddIn.xla]">
;<$Excel-Add-In "[#SomeOtherAddIn.xla]">
<$/Component>
;----------------------------------------------------------------------------
;--- Finish up and Add this header to the doco ------------------------------
;----------------------------------------------------------------------------
<$SourceFile HTML="Y" FileName="<?InputComponent>">
<$/Feature>