;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       AppVer() 
;; 
;;ACTION         Returns the version of a configured application component 
;;               such as IE, IIS, or SQL Server 
;; 
;;AUTHOR         Glenn Barnas  
;; 
;;VERSION        1.0  - 00/00/0000 
;; 
;;HISTORY        1.0  - 00/00/0000 - Initial Release 
;; 
;;SYNTAX         AppVer(appname [, server]) 
;; 
;;PARAMETERS     appname - Name of the EXECUTABLE (with or without .exe) 
;; 
;;REMARKS        Obtains app settings from a config file, then reads the version value 
;;               from the application executable file.  
;; 
;;RETURNS        Array - Version,Major,Minor 
;;               3-element array containing complete version value, the MAJOR version #, 
;;               and first digit of the MINOR version # 
;; 
;;EXIT CODES      0: Success 
;;               -1: No config file 
;;               -2: No Executable found 
;; 
;;DEPENDENCIES   AppInfo.INI file 
;; 
;;TESTED WITH    NT4, W2K, WXP 
;; 
;;EXAMPLES       None 
; 
Function AppVer($_App, OPTIONAL $_Target)
 
  Dim $_RegKey, $_RegVal, $_ExePath, $_Version, $_Major, $_Minor
  Dim $_Dest, $_Err, $_TrimCh, $_aVer
 
  $_ERR = 0  $_Dest = ''  $_Major = 0  $_Minor = 0
 
  ; insure '\\server\' format 
  $_Target =  IIf(CStr($_Target) <> '', '\\' + Join(Split(CStr($_Target), '\'), '', 3) + '\', '')
 
  ; Read the RegKey value from the config file 
  $_RegKey = ReadProfileString('\appinfo.ini', $_App, 'Key')
  $_RegVal = ReadProfileString('\appinfo.ini', $_App, 'Val')
  $_TrimCh = ReadProfileString('\appinfo.ini', $_App, 'Trim')
 
  ; Continue only if RegKey is defined 
  If $_RegKey <> ''
 
    ; Get the executable location from the registry 
    $_ExePath = ReadValue($_Target + $_RegKey, $_RegVal)
 
    ; Translate local path to remote if $Server is defined 
    If $_Target
      If Left($_ExePath,1) ='"'
        $_ExePath = SubStr($_ExePath,2,Len($_ExePath) - 2) 
      EndIf
      $_ExePath = Left($_ExePath,1) + Chr(36) + Right($_ExePath,Len($_ExePath) - 2) 
    EndIf
    ; read the version if the file exists 
    If Exist($_Target + $_ExePath)
      $_Version = GetFileVersion($_Target + $_ExePath, 'ProductVersion')
      $_ERR = @ERROR
      If $_TrimCh
        $_Version = Right($_Version, Len($_Version) - $_TrimCh)
      EndIf
 
      ; Obtain Major and first digit of Minor version 
      $_aVer = Split($_Version, '.', 2)
      $_Major = Val($_aVer[0])
      $_Minor = Val(Left($_aVer[1],1))
 
    Else
      $_ERR = -2 ; can't find executable 
    EndIf
  Else 		
    $_ERR = -1   ; Application not defined 
  EndIf
 
  $AppVer = $_Version,$_Major,$_Minor
 
  Exit $_ERR
 
EndFunction