Old 12th November 2009, 17:56   #1
bubunia2000
Junior Member
 
Join Date: Oct 2009
Posts: 19
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
bubunia2000 is offline   Reply With Quote
Old 12th November 2009, 18:36   #2
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
Easiest way is to write your version number to registry during install.
MSG is offline   Reply With Quote
Old 12th November 2009, 19:38   #3
bubunia2000
Junior Member
 
Join Date: Oct 2009
Posts: 19
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.
bubunia2000 is offline   Reply With Quote
Old 12th November 2009, 20:18   #4
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
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).
MSG is offline   Reply With Quote
Old 13th November 2009, 16:53   #5
sgiusto
Member
 
Join Date: Mar 2007
Location: Italy
Posts: 99
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
sgiusto is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump