I have been using a little NSIS script for a few years that grabs the version of the EXE so I can display it in the installers welcome text.
I got the script here: http://nsis.sourceforge.net/Invoking_NSIS_run-time_commands_on_compile-time
!define File "C:\MyFile.exe"
OutFile "GetVersion.exe"
SilentInstall silent
Section
## Get file version
GetDllVersion "${File}" $R0 $R1
IntOp $R2 $R0 / 0x00010000
IntOp $R3 $R0 & 0x0000FFFF
IntOp $R4 $R1 / 0x00010000
IntOp $R5 $R1 & 0x0000FFFF
StrCpy $R1 "$R2.$R3.$R4.$R5"
## Write it to a !define for use in main script
FileOpen $R0 "$EXEDIR\Version.txt" w
FileWrite $R0 '!define Version "$R1"'
FileClose $R0
SectionEnd
Recently I started using UPX to compress the EXE of the application.
Now that it is UPX compressed, the file version script no longer works, I'm guessing due to non standard header layout.
How can I read the file version from a UPX compressed EXE?
UPDATE: This is closed now but I discovered later this is likely to do with some kind of elevated permissions issue and running the command over a mapped drive.
Even when using UPX --ultra-brute test.exe
the version information block did not get compressed when I tried. Are you using special UPX switches? Have you tried --keep-resource=%resourceid%
?
If you are using NSIS v3 you can use !getdllversion
to get the version at compile-time without having to use !system
.