bubunia2000
12th November 2009 17:56 UTC
How to read version resource from the exe file
Hi all,
I read the NSIS documentation and found that we can add version tab to the generated EXE(VIAddVersionKey). If the installer wants to read the product version while installing to check whether that product version is already installed or not. Can it be possible in NSIS?
Cheers
Pradeep
MSG
12th November 2009 18:36 UTC
Easiest way is to write your version number to registry during install.
bubunia2000
12th November 2009 19:38 UTC
The reason Iam asking this way is I want when the exe is launched for installation I can query the registry whether the previous version exits or not in the registry. If it exists it will uninstall the earlier version and install the new instal else it will warn the user. So I need to know the "version info" prior the the launch of exe.
MSG
12th November 2009 20:18 UTC
I would suggest you make a !define at the top of your installer script. That way you can use the define everywhere (to compare to, and to write to the registry upon install), and when you compile a new version you only need to change the actual versionnumber once.
Example:
!define VERSIONNUM 3.1
Section
WriteRegStr HKCU "Software\YourCompany\YourApp" "VersionNumber" ${VERSIONNUM}
SectionEnd
At the beginning of the first section, read the version number from registry and compare it to ${VERSIONNUM}. If it's different, uninstall the previous version.
You can also use the VersionCompare function (see the wiki/google), to determine whether the previous install is a newer or an older version (in the .onInit function, for example).
sgiusto
13th November 2009 16:53 UTC
You can read the version of an executable using GetDLLVersion (it works for exe files with version resource too)
from the manual with some modifications:
GetDllVersion "$EXEPATH" $R0 $R1
IntOp $R2 $R0 / 0x00010000
IntOp $R3 $R0 & 0x0000FFFF
IntOp $R4 $R1 / 0x00010000
IntOp $R5 $R1 & 0x0000FFFF
StrCpy $0 "$R2.$R3.$R4.$R5"
this should give in $0 the version of the installer
hope this helps
Stefano