Author Topic: FileVerInfo checking  (Read 907 times)


  • Newbie
  • *
  • Posts: 3
FileVerInfo checking
« on: February 14, 2017, 06:17:55 am »
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

Code: [Select]
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

If FVersionx86 <"" || FVersionx64 <"" Then Message ("Incorrect Version", "Your must be at version 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 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)?


  • Tech Support
  • *****
  • Posts: 2441
    • WinBatch
Re: FileVerInfo checking
« Reply #1 on: February 14, 2017, 07:45:22 am »
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
if i <= nCnt then Message('Old Version', 'Time to upgrade')

"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates