#177888 - 2007-07-12 07:42 PM
How to Evaluate DisplayVersion in the Uninstall registry key
|
Witto
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
|
|
|
|
#177912 - 2007-07-13 10:02 AM
Re: How to Evaluate DisplayVersion in the Uninstall registry key
[Re: Sealeopard]
|
Witto
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
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
CompareVersions("0100","01") ?
CompareVersions("01","0100") ?
CompareVersions("100","1") ?
CompareVersions("1.0","10.0") ?
compareversions("10.0","4.0") ?
returns
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
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 |
CompareVersions("0100","01") ?
CompareVersions("01","0100") ?
CompareVersions("100","1") ?
CompareVersions("1.0","10.0") ?
CompareVersions("10.0","4.0") ?
returns
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1257 anonymous users online.
|
|
|