Function Reference


_VersionCompare

Compares two file versions for equality

#include <Misc.au3>
_VersionCompare ( $sVersion1, $sVersion2 )

Parameters

$sVersion1 The first version value
$sVersion2 The second version value

Return Value

Success: Following Values:
 0 - Both versions equal
 1 - Version 1 greater
-1 - Version 2 greater
Failure: @error will be set in the event of a catasrophic error

Remarks

This will try to use a numerical comparison but fall back on a lexicographical comparison.
See @extended for details about which type was performed.
Numerical version can be ended with a letter as "3.3.1c".

Example

#include <Misc.au3>
#include <MsgBoxConstants.au3>

Global $g_sResult = ""

Check_VersionCompare("25.2.1", "5.2.1", 1)
Check_VersionCompare("5.12.0", "5.2.1", 1)
Check_VersionCompare("10.0.0.0", "12,0,0,0", -1)

Check_VersionCompare("1.2.1", "1.10", -1)
Check_VersionCompare("1.11.1b", "1.2", 1)
Check_VersionCompare("1.1b", "1.11c", -1)
Check_VersionCompare("1.11b", "1.1c", 1)
Check_VersionCompare("5.2.1", "5.2.1a", -1)
Check_VersionCompare("5.2.1", "5.2.1", 0)
Check_VersionCompare("5.2.1", "5.2.1.0", 0)
Check_VersionCompare("5.2.1a", "5.2.1.0", 1)
Check_VersionCompare("5.2.1a", "5.2.1.1", -1)
Check_VersionCompare("5.2.1b", "5.2.1.1a", -1)
Check_VersionCompare("5.2.1b", "5.2.1a", 1)
Check_VersionCompare("5.2.1a", "5.2.1a", 0)
Check_VersionCompare("5.2.1a", "5.2.1b", -1)

MsgBox($MB_SYSTEMMODAL, '_VersionCompare Results', $g_sResult)

Func Check_VersionCompare($sVersion1, $sVersion2, $iReturn)
        Local $iRet = _VersionCompare($sVersion1, $sVersion2)
        Local $iExtended = @extended
        $g_sResult &= '"' & $sVersion1 & '" to "' & $sVersion2 & @TAB & " return " & $iRet
        If $iRet <> $iReturn Then $g_sResult &= " INSTEAD of " & $iReturn
        $g_sResult &= @TAB & "@extended = " & $iExtended & @CRLF
EndFunc   ;==>Check_VersionCompare