\
Tips and Tricks
Launch Conditions
MDAC not too old?
Launch Condition: MDAC not too old? |
This is an example of a macro call which will validate that
the level of MDAC your application requires is available:
<$ValidateMdacVersion LowestVersion="2.82">
The follow code is what actually implements the macro you used above:
#(
#define ValidateMdacVersion
;--- Validate parameters ------------------------------------------------
{$!:LOWESTVERSION} ;;Lists all valid parameters
;--- Make sure we know how to insert the file version compare code ------
#ifndef INCLUDE_VBSCRIPT_FUNCTION-CompareFileVersions
#error ^You must define the file version compare code in the{NL}macro "INCLUDE_VBSCRIPT_FUNCTION-CompareFileVersions",{NL}See the MAKEMSI tip in the manual!^
#endif
;--- Only allowed once (or specify the same version) --------------------
#ifdef @@CheckedMdacVersion
;--- This is not the first time, check same version! ----------------
#if ['<$@@CheckedMdacVersion>' <> '{$LowestVersion}']
#error ^You wish to check for MDAC "{$LowestVersion}" however you have previously also specified version "<$@@CheckedMdacVersion>"!^
#endif
#elseif
;--- First time so record the version and flag it -------------------
#define @@CheckedMdacVersion {$LowestVersion}
;--- Get the value from the registry (could also do in script) ------
#(
<$RegistryRead
Property="MDACVERSION"
HKEY="LOCAL_MACHINE"
KEY="Software\Microsoft\DataAccess"
NAME="FullInstallVer" ;;See MSDN Article #301202
>
#)
;--- Adjust the value to something Windows Installer can compare ----
<$VbsCa Binary="SeeIfMdacVersionIsHighEnough.vbs">
#( '<?NewLine>'
<$VbsCaEntry "Install">
;--- Init ---------------------------------------------------
dim RequiredVer, InstalledVer
RequiredVer = "{$LowestVersion}"
CaDebug 1, "Validating MDAC version (must be at least " & RequiredVer & ")"
InstalledVer = VbsCaPropertyGet("MDACVERSION", "2.52.5566", "")
CaDebug 2, "MDAC version " & InstalledVer & " is installed."
;--- Compare ------------------------------------------------
CaDebug 0, "Comparing the versions..."
dim CompRc, PropertyValue
CompRc = CompareFileVersions(InstalledVer, RequiredVer)
if CompRc = <$FILEVER_RC_F1_EQUAL_F2> or CompRc = <$FILEVER_RC_F1_GREATER_THAN_F2> then
PropertyValue = "OK"
else
PropertyValue = "ERROR"
end if
;--- set the property ---------------------------------------
CaDebug 0, "Setting property to: " & PropertyValue
session.Property("MDAC_STATUS") = PropertyValue
<$/VbsCaEntry>
;--- Add required compare function(s) ----------------------------
<$INCLUDE_VBSCRIPT_FUNCTION-CompareFileVersions>
#)
<$/VbsCa>
<$VbsCaSetup Binary="SeeIfMdacVersionIsHighEnough.vbs" Entry="Install" Seq="AppSearch-" SeqTable=^{$SeqTable='InstallUISequence InstallExecuteSequence'}^ TYPE="immediate" Key="SeeIfMdacVersionIsHighEnough.vbs" CONDITION=^<$CONDITION_INSTALL_ONLY>^>
;--- Now report any problem (could also be done in CA) --------------
#(
<$AbortIf
Condition=^MDAC_STATUS <> "OK"^
Message=^This product (<$ProdInfo.ProductName>) requires MDAC version {$LowestVersion} or later. Only MDAC version "[MDACVERSION]" is installed, please upgrade before trying again.^
Seq="AppSearch-"
SeqTable=^{$SeqTable}^
Key="AbortIfMdacVersionLessThan{$LowestVersion}"
>
#)
#endif
#)
The above code made use of a macro ("INCLUDE_VBSCRIPT_FUNCTION-CompareFileVersions")
described in the "File Version Compare Code" tip.