Handling Software Updates - An Example
Last week I wrote about a vexation with installs that I'm sure many of you have experienced--continually re-entering serial numbers and registration keys during upgrades. What I didn't supply at the time was a solution to the problem. I've been working on an update to Lazarus Registration that uses the new nsDialogs plugin, and I figured as long as I was in there I'd add a solution to the upgrade problem.
First, if you're using software registration in your NSIS installer, you're probably using some kind of custom page. Custom pages provide the perfect opportunity to insert your upgrade handling logic.
The core logic takes two parts. The first part is that after you've verified your registration information, you need to record the registration information into a known location. Since the system registry was designed for just such a use, that's what I'll recommend. So the leave function might contain the following:
WriteRegStr HKLM "Software\My Company\My App" "Serial" "$1"
WriteRegStr HKLM "Software\My Company\My App" "Registration" "$2"
This is assuming, of course, that $1 and $2 contain the validated serial number and registration key, respectively.
The second bit of logic actually comes in the creator function, and it's a little more complex:
ReadRegStr $0 HKLM "Software\My Company\My App" "Serial"
ReadRegStr $1 HKLM "Software\My Company\My App" "Registration"
; This is the custom registration DLL
regmyapp::NSISRegistered $0 $1
Pop $R2
${If} $R2 == "SUCCESS"
Abort
${EndIf}
To make my life a little easier I imported Logiclib.nsh, which gives me the nice If/EndIf syntax. I have also shown the syntax using a custom DLL from Lazarus Registration, just in case you were worried that I wouldn't get in the obligatory shameless plug.
The next release of Lazarus Registration will come with these features already available. The release also takes advantage of the capabilities of nsDialogs to produce a very nice registration screen that I'm pleased with.

![View your cart items []](/sites/all/modules/ecommerce/cart/images/cart_empty.png)
