
' Copyright 2002 Earth Resource Mapping Pty Ltd. This document contains unpublished source code of
' Earth Resource Mapping Pty Ltd. This notice does not indicate any intention to publish the source
' code contained herein.

' This will scan for plugins for all versions of Internet Explorer that have a VBscript engine version 2 or greater.
' This includes all versions of IE4 and beyond and some versions of IE 3.
' The script will only be called if this is known to be IE, Win32, VB2+

Function ECWCheckActiveX(activeXname, sECWVersion)

  on error resume next

  ' Need v2+ script engine to create objects
  If ScriptEngineMajorVersion >= 2 then
	Dim MyVersionObject
	Dim sVersion

	' Create an NCSVersion Object, new for Image Web Server v1.5+
	Set MyVersionObject = CreateObject("NCSVersion.NCSVersion.1")

  	If (err) then
		' No NCSVersion, definitely not installed
		ECWCheckActiveX = False
	Else
		' Got NCSVersion, need to get exact version and check
		ECWCheckActiveX = IsObject(MyVersionObject)	
 		
 		If(ECWCheckActiveX) then
			' Get version string
			sVersion = MyVersionObject.GetVersionString(activeXname)

			If (err) then
				' Error: either GetVersionString() doesn't exist, or NCSView wasn't found.
				ECWCheckActiveX = False
			Else
				' Got the version, check it's good enough.
				' If ok, will fall through checks, ECWCheckActiveX already true from IsObject() above.

				' Split up into major, minor, sub and build.
				VerArray = Split(sVersion, ",", 4, vbTextCompare)
				ECWVerArray = Split(sECWVersion, ",", 4, vbTextCompare)

				nV1 = Int(VerArray(0))
				nV2 = Int(ECWVerArray(0))

				If (nV1 < nV2) then
					' Major version too old.
					ECWCheckActiveX = False
				Else 
					If (nV1 = nV2) then 
						' Same Major version, check minor
						nV1 = Int(VerArray(1))
						nV2 = Int(ECWVerArray(1))

						If (nV1 < nV2) then	
							' Minor too old
							ECWCheckActiveX = False
						Else
							If (nV1 = nV2) then 
								' Same minor version, check sub
								nV1 = Int(VerArray(2))
								nV2 = Int(ECWVerArray(2))

								If (nV1 < nV2) then
									' Sub too old
									ECWCheckActiveX = False
								Else
									If (nV1 = nV2) then 
										' Same sub, check build number
										nV1 = Int(VerArray(3))
										nV2 = Int(ECWVerArray(3))

										If (nV1 < nV2) then
											' Build number too old
											ECWCheckActiveX = False
										End If	
									End If						
								End If	
							End If				
						End If	
					End If
				End If
			End If			
		End If	
	End If

	Set MyVersionObject = Nothing
  Else
	ECWCheckActiveX = False
  End If
End Function
