FileVerInfo checking

Started by TSFleming, February 14, 2017, 06:17:55 AM

Previous topic - Next topic

TSFleming

I apologize in advance for such a simple question to my embarrassingly primitive WinBatch script.  I'm trying to determine if an upgrade can take place based on the version of a file.  In this example the file version (Program.exe) is 1.6.0.5


Filex86 = "C:\Program Files\Program.exe"
Filex64 = "C:\Program Files (x86)\Program.exe"
Filex86ex = FileExist ("%Filex86%")
Filex64ex = FileExist ("%Filex64%")
FVersionx86=FileVerInfo(FVWx86, "", "FileVersion")
FVersionx64=FileVerInfo(FVWx64, "", "FileVersion")

If Filex86ex == "" & Filex64ex == "" Then GoTo COPY
Else GoTo VERSION

:VERSION
If FVersionx86 <"1.6.0.0" || FVersionx64 <"1.6.0.0" Then Message ("Incorrect Version", "Your must be at version 1.6.0.0 or higher to upgrade.")

Else GoTo COPY


Under VERSION I'm trying to determine if Program.exe (whether FVersionx86 OR FVersionx64) is less than version 1.6.0.0 to abort or if greater proceed.  I've tried both Logical and Bitwise OR operators yet I get the message my version is the incorrect version rather than proceeding as I'm expecting it to.

In this instance what would be the correct way to determine if either of these files exists (there will be only one)?

td

There isn't a best way to compare file version information from a files resource area because version information is not standardize.   A files version format can also change between releases and some files don't even have version information.  When present, it is often better to use the numeric format version information (#FileVesion) instead of the string format you are using now because it is more likely to follow a pattern and is easier to use in comparisons. The numeric format is also the format usually displayed by an Explorer shell window when you view a files 'details' from the properties context menu on newer versions of Windows.

Also keep in mind that performing comparisons on strings with numeric values does not always produce the expected results.  For example,

if "10.0.0" < "2.0.0" then Pause("Stupid Computer", "It reports that version 10 is older than 2")

So the first thing you need to do is determine which version information is available in you file and determine it's format.  You can then determine the best approach to comparing versions of the targeted file.

One common strategy is to use numeric version information and use the StrReplace function to remove the commas.

Version = StrReplace(Version, ',','')
if Version > OldVersion ...

Of course the above only works when the comma striped numeric value fits into a 32-bit integer.  If the version number it to large to fit into a 32-bit integer, you may be able to use the ItemExtract function in a loop to compare each element of the version.

The following  makes several assumptions that my not hold in your case but it demonstrates using ItemExtract to compare version information.

nCnt = ItemCount(NewVer, ',')
for i = 1 to nCnt
   if ItemExtract(i, OldVer, ',') < ItemExtract(i, NewVer, ',') then break
next
if i <= nCnt then Message('Old Version', 'Time to upgrade')



"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade