PeterPWN Posted August 6, 2010 Share Posted August 6, 2010 (edited) Hi, I have the following Problem: I have an Autoit Script, that runs via Group Policy Logon Script on the Host PC and checks the File Version there with an ini File on the Server. When the two Versions are different it runs the installer script to install the newest program. ( I edit the ini File and the newest Installer once I got them) The Problem is now: When I'm on holiday or whatever and some User installs a newer Version of a Program than is on the server, the Script installs the old program again once the user logs on since the two versions differ. So I need a way to somehow check if the Version on the PC is newer than the one in the ini file. The File currently looks like this: [Java] Version=6.0.210.6 Version=10.1.53.64 [AdobeReader] Version=9.3.3 [Firefox] Version=3.6.8 (de) Thank you The best way to deal with that Problem would be to Download new Updates automatically and Update the Ini File, but i guess that would be too complex ^^ Edited August 6, 2010 by PeterPWN Link to comment Share on other sites More sharing options...
NiVZ Posted August 6, 2010 Share Posted August 6, 2010 (edited) Instead of checking if the version numbers are different, why don't you just check if the version on the PC is less than the version in the INI file? That way it won't run if the PC has a newer version than the server eg: If $PCVersion < $ServerVersion Then ; Run Installer EndIf For checking the version on the PC you can use FileGetVersion, or loop through HKEY_LOCAL_MACHINE\Software\Microsoft\CurrentVersion\Uninstall looking at DisplayName and DisplayVersion NiVZ Edited August 6, 2010 by NiVZ Link to comment Share on other sites More sharing options...
water Posted August 6, 2010 Share Posted August 6, 2010 (edited) But be aware that you do a string compare so the results might be wrong. You have to make the strings "compareable". #include <array.au3> ; String compare $sV1 = "10.9.17" $sV2 = "10.10.3" If $sV1 > $sV2 Then ConsoleWrite($sV1 & " > " & $sV2 & @CRLF) Else ConsoleWrite($sV1 & " <= " & $sV2 & @CRLF) EndIf ; Make strings comapreable $aV1 = StringSplit($sV1,".") $aV2 = StringSplit($sV2,".") For $iIndex = 1 To $aV1[0] $aV1[$iIndex] = StringFormat("%05s",$aV1[$iIndex]) Next For $iIndex = 1 To $aV2[0] $aV2[$iIndex] = StringFormat("%05s",$aV2[$iIndex]) Next $sV1New = _ArrayToString($aV1,".",1) $sV2New = _ArrayToString($aV2,".",1) If $sV1New > $sV2New Then ConsoleWrite($sV1 & " > " & $sV2 & @CRLF) Else ConsoleWrite($sV1 & " <= " & $sV2 & @CRLF) EndIf A special treatment needs Firefox as this has version and language information combined. Edited August 6, 2010 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
PeterPWN Posted August 6, 2010 Author Share Posted August 6, 2010 (edited) Edit: Lol just came up with that idea @Water Well just < won't work. I wrote a func to check my versions now, I hope that works: func compareVersion($var, $var2) $test = StringSplit($var,".") $test2 = StringSplit($var2,".") For $i = 1 to $test[0] $ret = 0 If number($test[$i]) > number($test2[$i]) Then $ret = 1 ExitLoop ElseIf number($test[$i]) = number($test2[$i]) Then Else $ret = 2 ExitLoop EndIf Next Return $ret EndFunc Edited August 6, 2010 by PeterPWN Link to comment Share on other sites More sharing options...
PeterPWN Posted August 6, 2010 Author Share Posted August 6, 2010 (edited) I checked with Firefox though but that still works fortunately I still have a problem when it comes to this: $ver = "3.5.8" $ver2 = "3.5.8.3" Edited August 6, 2010 by PeterPWN Link to comment Share on other sites More sharing options...
PeterPWN Posted August 6, 2010 Author Share Posted August 6, 2010 Ok My final function looks like this now: func compareVersion($var, $var2) $aVar1 = StringSplit($var,".") $aVar2 = StringSplit($var2,".") If $aVar1[0] > $aVar2[0] Then $length = $aVar2[0] Else $length =$aVar1[0] EndIf For $i = 1 to $length $ret = 0 If number($aVar1[$i]) > number($aVar2[$i]) Then $ret = 1 ExitLoop ElseIf number($aVar1[$i]) = number($aVar2[$i]) Then If $aVar1[0] > $aVar2[0] Then $ret = 1 ElseIf $aVar1[0] < $aVar2[0] Then $ret = 2; EndIf Else $ret = 2 ExitLoop EndIf Next Return $ret EndFunc If someone knows a way how to auto update these Programs though I'm glad to hear it Link to comment Share on other sites More sharing options...
ibroadbent Posted November 20, 2012 Share Posted November 20, 2012 (edited) Thanks for this function, very handy for checking versions of Flash, Adobe Reader etc. when deploying s/w with SCCM (because data in SCCM database can lag a day or more behind what's actually on the PC.) Minor rewrite of the function with comments: #include <Math.au3> ; needed for _min function func CompareVersion($var1, $var2) ; Function to compare number strings e.g. "5.20.3456" to "6.0.23" — Converts the string into an array ; returns 1 if first number is bigger (or same); returns 2 if second number is bigger $aVar1 = StringSplit($var1,".") ;split each version number string into an array of integers $aVar2 = StringSplit($var2,".") $length = _min($aVar1[0], $aVar2[0]) ; get the smaller number of array elements in the two version strings For $i = 1 to $length If number($aVar1[$i]) > number($aVar2[$i]) Then $ret = 1 ; 1st string is later version ExitLoop ElseIf number($aVar1[$i]) < number($aVar2[$i]) Then $ret = 2 ; 2nd string is later version ExitLoop Else ; "i"th element is the same... $ret = 1 If $aVar1[0] < $aVar2[0] Then $ret = 2 ; 2nd string is bigger if it has more elements and all previous elements are the same EndIf ; keep looping if not at the lowest common no. of elements yet Next Return $ret EndFunc Edited November 21, 2012 by ibroadbent Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now