;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       CompareVerString() 
;; 
;;ACTION         Compares two version strings ("." delimited) 
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION        1.1  - 2011/09/27 
;; 
;;HISTORY        1.0  - 2009/03/01 - Initial Release 
;;               1.1  - 2011/09/27 - Improved compare logic 
;; 
;;SYNTAX         CompareVerString(Version1, Version2) 
;; 
;;PARAMETERS     Version# - REQUIRED - Version strings to compare 
;; 
;;REMARKS        Compares the two versions, returns -1 if V2<V1, 0 if V2=V1, 
;;               and 1 if V2>V1 
;; 
;;RETURNS        Integer: -1, 0, or 1 depending on match 
;; 
;;DEPENDENCIES   none 
;; 
;;TESTED WITH    W2K, WXP, W2K3, Vista, X64 
;; 
;;EXAMPLES       $Version = GetFileVersion('file.ext') 
;;		 If CompareVerString('2.46.55.0', $Version) >= 0 
;;		   'Application is installed and current!' ? 
;;		 Else 
;;		   'Application must be upgraded!' ? 
;;		 EndIf 
;; 
; 
Function CompareVerString($_Version1, $_Version2)
 
  Dim $_X, $_Max, $_Val, $_Wt			; Index, Max, Value & Weight vars 
  Dim $_Vf1, $_Vf2				; version string arrays 
 
  $CompareVerString = 0				; Default to match 
 
  $_Version1 = Split($_Version1, '.')		; get version as array of elements 
  $_Version2 = Split($_Version2, '.')
 
  $_Vf1 = UBound($_Version1)			; elements in version1 array 
  $_Vf2 = UBound($_Version2)			; elements in version2 array 
 
  ; insure that both version strings have the same number 
  ; of fields - missing fields are set to 0. 
  Select					; find highest value 
   Case $_Vf1 = $_Vf2
    $_Max = $_Vf1
   Case $_Vf1 < $_Vf2
    $_Max = $_Vf2
    ReDim Preserve $_Version1[$_Max]		; adjust array and init new values 
    For $_X = ($_Vf1 + 1) to $_Max $_Version1[$_X] = 0 Next
   Case $_Vf1 > $_Vf2
    $_Max = $_Vf1
    ReDim Preserve $_Version2[$_Max]		; adjust array and init new values 
    For $_X = ($_Vf2 + 1) to $_Max $_Version2[$_X] = 0 Next
  EndSelect
 
  ; Compare each element pair in the version strings, starting with the least-significant 
  ; If the element values are equal, they are effictively ignored. If the desired value 
  ; is greater than the installed value, the current Match Value is added to the weight, but 
  ; if the desired value is less than the installed value, the current Match Value is  
  ; subtracted from the weight. The Match Value is increased in binary form as the  
  ; significance of the version values increases. This allows mis-matched string comparisons, 
  ; such as "3.0" and "2.46.24.5", to be processed correctly. 
  $_Val = 1					; current match value 
  $_Wt = 0					; match weight 
  For $_X = $_Max to 0 Step -1
    Select
     Case Right('0000000000' + $_Version1[$_X], 10) < Right('0000000000' + $_Version2[$_X], 10)
      $_Wt = $_Wt + ($_Val * -1)
     Case Right('0000000000' + $_Version1[$_X], 10) > Right('0000000000' + $_Version2[$_X], 10)
      $_Wt = $_Wt + $_Val
    EndSelect
    $_Val = $_Val * 2
  Next
 
  Select
   Case $_Wt > 0
    $CompareVerString = -1			; Version 2 < Version1 
   Case $_Wt = 0
    $CompareVerString = 0			; Version 2 = Version1 
   Case $_Wt < 0
    $CompareVerString = 1			; Version 2 > Version1 
  EndSelect
 
  Exit 0
 
EndFunction