Archive: Trouble getting file version


Trouble getting file version
I'm trying to get a file version and after calling GetFileVersion, the return value is always empty. I know the file exists (I've tried this on a number of files) and that there is version data in the file. I've tried using my Var and R0 to capture the result, both return an empty string.

It sounds like maybe I'm not getting the library setup properly (i.e. like having to call StrStr before it will work), but I can't seem to find any hints. Here is a code snippet. The syntax looks pretty straighforward, so I'm not sure what I'm doing wrong. This is just test code now so I'm aborting after some debugging message boxes. I'm on version 2.16.

Any clues?

!include "FileFunc.nsh"
!include "WordFunc.nsh"
!include "TextFunc.nsh"
!include "StrFunc.nsh"
${StrStr} ;Activate the StrStr Function
!insertmacro GetFileVersion
!insertmacro VersionCompare
!insertmacro LineFind
!insertmacro WordReplace

...
...

Function .onInit
Var /GLOBAL INSTALLED_VERSION

IfFileExists "$PROGRAMFILES\foo\foo.exe" 0 NoErrorMsg

; See what version it is
${GetFileVersion} '$PROGRAMFILES\foo\foo.exe' $INSTALLED_VERSION
MessageBox MB_OK "$(INSTALLED_VERSION)"
MessageBox MB_OK "${VERSION}"
Abort


; Check version status
${VersionCompare} $INSTALLED_VERSION ${VERSION} $INSTALLED_VERSION

IntCmp 1 $R0 downgrade upgrade CurrentVer

CurrentVer:
MessageBox MB_OK "current"
Abort

downgrade:
MessageBox MB_OK "older"
Abort

upgrade:
MessageBox MB_OK "Upgrade"
Abort

NoErrorMsg:


FunctionEnd


Hi!

You can use the following method for getting File Version:

;declare variables before the section
Var Out2
Var Out3
Var BundledExe1 ; foo.exe (this will contain your/developer's latest version of foo.exe)

Now add the following coding inside your section:
;supply your latest exe's(foo.exe) version no.
StrCpy $BundledExe1 "5.168.0.33"
;To fetch ver.info of user's exsisting foo.exe
${GetFileVersion} '$INSTDIR\foo.exe' $OUT2
;OUT2 variable will contain the file version of foo.exe
;you can use the messagebox to check it.

;now go for version compare of your and user's copy of foo.exe:
${VersionCompare} $BundledExe1 $OUT2 $OUT3
; $OUT3=0 Versions are equal
; $OUT3=1 Version1 is newer
; $OUT3=2 Version2 is newer
${If} $OUT3 = 1
;take action as per your requirement
${ElseIf} $OUT3 = 2
;take action as per your requirement
${ElseIf} $OUT3 = 0
;take action as per your requirement
${EndIf}


I'm using this coding for real-life project and its working fine.

With regards,
Swapan Das


You don't use parenthesis on variables.
E.g.
Bad: $(INSTALLED_VERSION)
Good: $INSTALLED_VERSION

-Stu