Page 1 of 1 1
Topic Options
#177888 - 2007-07-12 07:42 PM How to Evaluate DisplayVersion in the Uninstall registry key
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
I am trying to create a script that installs software on certain conditions. One of these conditions would be that the DisplayVersion in the Uninstall key in the registry is older than that of the new software.

These install strings have all kinds of formats. If it is just something like
"12.34.5678.0234"
it is not difficult to evaluate that
"13.00.0001.0001"
is more recent. just split with as delimiter the "." and evaluate the integer values in the array.

Here is a short piece of code that I got out of my script

Break ON

DIM $strUninstallRegPath, $strUninstallRegKey
DIM $strDisplayVersion, $arrDisplayVersion

$strUninstallRegPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
$strUninstallRegKey = "{8CAC1600-0BBE-499A-A9E9-5F334DBC8E89}"
$strDisplayVersion = "09.02.0100.1935"
$arrDisplayVersion = Split($strDisplayVersion, ".")

DIM $arrVersion
$arrVersion = Split(ReadValue($strUninstallRegPath + $strUninstallRegKey, "Displayversion"), ".")
If UBound($arrVersion) = UBound($arrDisplayVersion)
   
DIM $a
    For $a = 0 To UBound($arrDisplayVersion)
       
If CINT($arrDisplayVersion[$a]) > CINT($arrVersion[$a])
            fnInstallSoftware(
$strServer, $strPath, $strFile, $strSwitches)
           
Exit @ERROR
        EndIf
    Next
    Exit @ERROR
Else
    Exit 87
EndIf


But several kind of software have DisplayVersions like (just walking through my registry):
  • 6.00 H1
  • 1.4.2_06
  • 2.00 C3
  • 1.5.0.631.36.F

Does anybody know a smarter way to evaluate DisplayVersion strings?
Per example: "6.00 I0" would be more recent than "6.00 H1"
What would be a good way to evaluate this?

Top
#177890 - 2007-07-12 07:54 PM Re: How to Evaluate DisplayVersion in the Uninstall registry key [Re: Witto]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hmmm...
we had kixtart golf tournament of humansorter.
think that code is exactly suitable to your needs.
_________________________
!

download KiXnet

Top
#177896 - 2007-07-12 10:46 PM Re: How to Evaluate DisplayVersion in the Uninstall registry key [Re: Lonkero]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Indeed. Looked it up.
The code Benny posted
ok had to revert back to an earlier code, this one has no hard-coded length.
looks good and is not too "golfed".

Top
#177907 - 2007-07-13 06:00 AM Re: How to Evaluate DisplayVersion in the Uninstall registry key [Re: Witto]
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
What about the CompareVersions UDF?
_________________________
There are two types of vessels, submarines and targets.

Top
#177912 - 2007-07-13 10:02 AM Re: How to Evaluate DisplayVersion in the Uninstall registry key [Re: Sealeopard]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Jens,
Gave it a quick try.
cool
Thanks

Top
#177952 - 2007-07-14 02:24 AM Re: How to Evaluate DisplayVersion in the Uninstall registry key [Re: Witto]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Jens,
I like your modified UDF
But I would think that a version 1 and a version 10 of a package have to be different
Also a version 10 seems older than a version 4
 Code:
CompareVersions("0100","01") ?
CompareVersions("01","0100") ?
CompareVersions("100","1") ?
CompareVersions("1.0","10.0") ?
compareversions("10.0","4.0") ?

returns
 Code:
0
0
0
0
-1

I would presume that only the first part of a version, before the first delimiter (dot or comma) should be handled in a different way. More like in the "Human Sort" way.

Top
#177961 - 2007-07-15 01:12 AM Re: How to Evaluate DisplayVersion in the Uninstall registry key [Re: Witto]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Jens,
I think the logic for the first comparison has to be reverted. The right part has to be compared. For the rest, the left part has to be compared like you do.
Here is a proposal for a modified CompareVersions() UDF
Function compareversions($Ver1, $Ver2, OPTIONAL $Limit)
   
DIM $sourcever, $destver, $level, $maxlevel, $pad, $maxpad
   
   
If Trim($ver1)='' Or Trim($ver2)=''
        $compareversions=-2
       
Exit -2
   
EndIf
   
   
If VarType($limit)
       
$limit=Val($limit)
   
Else
        $limit=999
   
EndIf
   
   
If InSTR($ver1,'.')
       
$sourcever=Split($ver1,'.')
   
Else
        $sourcever=Split($ver1,',')
   
EndIf
    If InSTR($Ver2,'.')
       
$destver=Split($ver2,'.')
   
Else
        $destver=Split($ver2,',')
   
EndIf
   
   
$level=0
   
$maxlevel=UBound($sourcever)
   
If $maxlevel($destver)
       
$maxlevel=UBound($destver)
   
EndIf
    ReDIM preserve $sourcever[$maxlevel], preserve $destver[$maxlevel]
   
Do
        $ver1=Trim($sourcever[$level])
       
$ver2=Trim($destver[$level])
       
If Len($ver1)>Len($ver2)
           
$maxpad=Len($ver1)
       
Else
            $maxpad=Len($ver2)
       
EndIf
        For $pad=1 To $maxpad
            If $level = 0
               
$ver1='0'+$ver1
                $ver2='0'+$ver2
            Else
                $ver1=$ver1+'0'
                $ver2=$ver2+'0'
            EndIf
        Next
        If $Level = 0
           
$ver1=Right($ver1,$maxpad)
           
$ver2=Right($ver2,$maxpad)
       
Else
            $ver1=Left($ver1,$maxpad)
           
$ver2=Left($ver2,$maxpad)
       
EndIf
        Select
            Case $ver1>$ver2
                $compareversions=1
           
Case $ver1<$ver2
                $compareversions=-1
           
Case 1
               
$compareversions=0
       
EndSelect
        $level=$level+1
   
Until $level>$maxlevel Or $compareversions<>0 Or $level>$limit
    Exit 0
EndFunction

 Code:
CompareVersions("0100","01") ?
CompareVersions("01","0100") ?
CompareVersions("100","1") ?
CompareVersions("1.0","10.0") ?
CompareVersions("10.0","4.0") ?

returns
 Code:
1
-1
1
-1
1

Top
#177962 - 2007-07-15 03:56 AM Re: How to Evaluate DisplayVersion in the Uninstall registry key [Re: Witto]
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Thanks, Witto.

Updated the UDF with your version. UDF is at CompareVersions() - Compares two multi-segment version strings
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1808 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.061 seconds in which 0.04 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org