The "AbortIf" Command |
This command is used as a simple way to create a custom action 19 (or "LaunchCondition") which tests a "condition" and if true terminates Windows Installer with an error message.
For more complex conditions than Windows Installer can handle you could use the "VbsCa" command.
The macro takes these parameters:
I have captured a large number of "sample properties" which could be used in any conditions. Note that the values of some properties may not be available at all times and in some cases are modified during processing.
If the parameter is supplied then if its blank then a sequence number will be assigned otherwise the specified value will be used. This sequence number will typically be after some custom action code you may have invoked to set some property to indicate whether the install should proceed or not.
The sequencing information (see some default sequencing) can be supplied in a number of formats:
Basically you describe a range of valid values and whether you prefer the value to be chosen from the lower (default) or higher end.
The range should be specified in the format "lower - higher". Either value can be omitted, be specified as an integer such as "1000" or the name of an action such as "InstallFiles". The default value for the lower end is "1" and for the higher "32767" and leading and trailing spaces for each are stripped. The minimum and maximum values can be returned as the range is inclusive.
By default MAKEMSI will choose a number as close as possible to the lower end, if you wish it to be as high as possible then begin the specification string with "<".
Some Examples:
You should of course be aware of what your script does, for example if it moves a custom action that you have already sequenced other actions relative to then that would probably be "bad"!
EXAMPLE 1 |
We only want to install this product on Windows 2000, XP or above:
<$AbortIf Condition=^not VersionNT OR (VersionNT < 500)^ Message=^Can only be installed on Windows 2000, XP or greater.^>
The condition "not VersionNT" is checking to see if the "VersionNT" property exists (it won't for WIN95, WIN98 and WINME) and "VersionNT < 500" is checking if the NT version is less than "5.00" (correct value for WIN2000).
See the online documentation for a list of operating system related property values.
EXAMPLE 2 |
;--- Define the list of properties we require (3 in this case) -------------- #( ";" #define REQUIRED_MSIEXEC_PROPERTIES CENTRAL_SERVER LOCAL_SERVER SOME_OTHER_THIRD #) ;--- Make sure they exist --------------------------------------------------- #{ SET ^Property={;}<$REQUIRED_MSIEXEC_PROPERTIES>^ #( ;--- Test for non-existance of property (INSTALL time only) ---------- <$AbortIf Condition=^NOT <??SET_Property> and not Installed^ Message=^The property "<??SET_Property>" must be specified on the MSIEXEC command line during installation. The complete list is "<$REQUIRED_MSIEXEC_PROPERTIES>"!^ > #) #}
EXAMPLE 3 - Macro to Find "WSCRIPT.EXE" |
;################################################################################## ;### Note that I have now created a "FileFindInListedDirs" command ;### which simplifies this and makes it more generic: ;### <$FileFindInListedDirs File="wscript.exe" DIRS="System64Folder;SystemFolder;WindowsFolder"> ;################################################################################## ;---------------------------------------------------------------------------- ;--- Macro to find "WSCRIPT.EXE" ;--- MS stupidly places this file in logically different locations ;--- ("C:\windows" in WIN98). Also just to make it more difficult it is not ;--- possible to search by attribute, or search path and thus not possible ;--- to avoid possible incorrect matches in fixpack backup directories. ;--- All in all nearly a handful of reasons to swear at MS in one go.... ;---------------------------------------------------------------------------- #( #define WSCRIPT.EXE ;--- Can't do this! Can find files in "$NtServicePackUninstall" type directories --- ;<$FileFind File="WSCRIPT.EXE" Property="WSCRIPT.EXE" PATH="[WindowsFolder]" Depth="1"> ;;Danger, Danger... ;--- Thanks MS... ------------------------------------------------------- <$FileFind File="WSCRIPT.EXE" Property="WSCRIPT.EXE.WF" PATH="[WindowsFolder]" Depth="0" Default=""> <$FileFind File="WSCRIPT.EXE" Property="WSCRIPT.EXE.SF" PATH="[SystemFolder]" Depth="0" Default=""> <$PropertyCa "WSCRIPT.EXE" Value="[WSCRIPT.EXE.WF]" Seq="AppSearch-" Condition="WSCRIPT.EXE.WF and (<$CONDITION_EXCEPT_UNINSTALL>)" SeqTable="InstallUISequence InstallExecuteSequence"> <$PropertyCa "WSCRIPT.EXE" Value="[WSCRIPT.EXE.SF]" Seq="AppSearch-" Condition="WSCRIPT.EXE.SF and (<$CONDITION_EXCEPT_UNINSTALL>)" SeqTable="InstallUISequence InstallExecuteSequence"> <$AbortIf Condition="not WSCRIPT.EXE and (<$CONDITION_EXCEPT_UNINSTALL>)" Message=^The file "WSCRIPT.EXE" was not found in the "[WindowsFolder]" or "[SystemFolder]" directories!^ SeqTable="InstallUISequence InstallExecuteSequence" Seq="AppSearch-" > <$PropertyList "SecureCustomProperties" Value="WSCRIPT.EXE"> #)