Before you can do anything, you need to login to your LimeLM account (or sign up) and download the TurboActivate.zip. This zip contains the TurboActivate.dll & TurboActivate.exe along with source code examples.
We're going to walk you through each step you need to add licensing to your NSIS installer. By the end of this walkthrough you'll have added a product key page to your installer that will verify & activate the product key and will also deactivate the user when they uninstall your app:
This tutorial and the example code can be used with either the ANSI or the Unicode version of NSIS. We recommend you use at least version 2.46 of NSIS because we make use of some newer features of NSIS (Modern UI 2, NSDialogs, etc.).
If you haven't already signed up for LimeLM then sign up now. All plans have a 30-day free trial. Or, if you're just putting your toes in the water, there's even a free plan that has no time limit and doesn't require a credit card.
After you've created your account download TurboActivate.zip and extract it anywhere. After you extract it you'll find 3 folders:
If you haven't already created a new product in LimeLM, do it now. You can change any value later, so don't worry about making a mistake.
Go to your version page in LimeLM. Download the "TurboActivate.dat" file. Include this file with all the other files you'll be including with your installer. In the example NSIS you'd put this TurboActivate.dat file in the same folder as the "Example.nsi" file.
Next copy "TurboActivate.dll" from the x86 folder you extracted. Put this file in the same folder you just copied the TurboActivate.dat file to.
If you're modifying your own NSIS installation script (instead of using our Example.nsi script) then you need to make sure you're referencing the following headers:
!include LogicLib.nsh !include nsDialogs.nsh !include WinVer.nsh
Now you need to set the version GUID in your installer. On your version page in LimeLM (the page where you downloaded the TurboActivate.dat file) copy the Version GUID. Add the following lines near the top of your script:
!define VersionGUID 'Paste GUID Here' !define REQUIRE_PKEY !define REQUIRE_ACT
Replace the "Paste GUID Here" string with the Version GUID string your copied from your version page.
To add TurboActivate to your installer so that your installer, your app, and your uninstaller can use the TurboActivate functions you need to do a few things. In this example we've been assuming both the TurboActivate.dll and TurboActivate.dat files are in the same folder as your "*.nsi" NSIS installation script.
ReserveFile "TurboActivate.dll" ReserveFile "TurboActivate.dat"
Function .onInit ; ... Your other lines ; TurboActivate requires at least Windows XP ${IfNot} ${AtLeastWinXP} MessageBox MB_OK "Windows XP (or newer) is required to run $(^NameDA)." Quit ${EndIf} ; create the plugins folder InitPluginsDir ; extract the TurboActivate files to the plugns folder File /oname=$PLUGINSDIR\TurboActivate.dll "TurboActivate.dll" File /oname=$PLUGINSDIR\TurboActivate.dat "TurboActivate.dat" FunctionEnd
SetOutPath "$INSTDIR" File "TurboActivate.dll" File "TurboActivate.dat"
Section "Uninstall" ; Set the output path to the installation directory so we can call TurboActivate SetOutPath $INSTDIR ; check if activated System::Call "TurboActivate::IsActivated(w'${VersionGUID}') i.r2 ? cu" ; deactivate if activated ${If} $2 == 0 System::Call "TurboActivate::Deactivate(i1) i.r2 ? cu" ${EndIf} ; Set the output directory to the temp folder where this uninstaller resides ; so we can delete the '$INSTDIR'. Otherwise the earlier "SetOutPath" locks the ; "$INSTDIR" making it impossible to delete. SetOutPath $EXEDIR ;ADD YOUR OWN FILES HERE... Delete "$INSTDIR\TurboActivate.dll" Delete "$INSTDIR\TurboActivate.dat" Delete "$INSTDIR\Uninstall.exe" RMDir "$INSTDIR" SectionEnd
The next step is create the product key page. We've done this work for you in the Example.nsi file. First add the custom page in your installer page order:
!insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Docs\Modern UI\License.txt" Page custom PagePKey PagePKeyLeave !insertmacro MUI_PAGE_COMPONENTS !insertmacro MUI_PAGE_DIRECTORY !insertmacro MUI_PAGE_INSTFILES
Then add the handler functions for the page:
Var txtPKey Function PagePKey ; Skip this page if we're already activated System::Call "TurboActivate::IsActivated(w'${VersionGUID}') i.r2 ? c" ${If} $2 == 0 Abort ${EndIf} !insertmacro MUI_HEADER_TEXT "Type your product key" "" nsDialogs::Create 1018 Pop $0 nsDialogs::CreateControl STATIC ${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS} 0 0 0 100% 30 "You can find the $(^NameDA) product key in the email we sent you. Activation will register the product key to this computer." Pop $0 nsDialogs::CreateControl STATIC ${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS} 0 0 50 100% 20 "Product Key:" Pop $0 nsDialogs::CreateControl EDIT ${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS}|${ES_AUTOHSCROLL}|${WS_TABSTOP} ${WS_EX_CLIENTEDGE} 0 75 100% 12u "" Pop $txtPKey ; focus the product key box SendMessage $HWNDPARENT ${WM_NEXTDLGCTL} $txtPKey 1 nsDialogs::Show FunctionEnd Function PagePKeyLeave ; get the product key in WCHAR * form, put on $0 System::Call user32::GetWindowTextW(i$txtPKey,w.r0,i${NSIS_MAX_STRLEN}) ; check if the product key is valid System::Call "TurboActivate::CheckAndSavePKey(wr0, i1) i.r2 ? c" ; require the product key if we're requiring the activation !ifdef REQUIRE_ACT !ifndef REQUIRE_PKEY !define REQUIRE_PKEY !endif !endif ${If} $2 == 0 ; try to activate, show a specific error if it fails System::Call "TurboActivate::Activate() i.r2 ? c" !ifdef REQUIRE_ACT ${Switch} $2 ${Case} 0 ; successful Goto actSuccess ${Case} 2 ; TA_E_PKEY MessageBox MB_OK|MB_ICONSTOP "The product key is invalid or there's no product key." ${Break} ${Case} 4 ; TA_E_INET MessageBox MB_OK|MB_ICONSTOP "Connection to the server failed." ${Break} ${Case} 5 ; TA_E_INUSE MessageBox MB_OK|MB_ICONSTOP "The product key has already been activated with the maximum number of computers." ${Break} ${Case} 6 ; TA_E_REVOKED MessageBox MB_OK|MB_ICONSTOP "The product key has been revoked." ${Break} ${Case} 8 ; TA_E_PDETS MessageBox MB_OK|MB_ICONSTOP "The product details file 'TurboActivate.dat' failed to load. It's either missing or corrupt." ${Break} ${Case} 11 ; TA_E_COM MessageBox MB_OK|MB_ICONSTOP "CoInitializeEx failed." ${Break} ${Case} 13 ; TA_E_EXPIRED MessageBox MB_OK|MB_ICONSTOP "Failed because your system date and time settings are incorrect. Fix your date and time settings, restart your computer, and try to activate again." ${Break} ${Default} MessageBox MB_OK|MB_ICONSTOP "Failed to activate." ${Break} ${EndSwitch} !endif ${Else} !ifdef REQUIRE_PKEY MessageBox MB_OK|MB_ICONSTOP "You must enter a valid product key." ; focus the product key box SendMessage $HWNDPARENT ${WM_NEXTDLGCTL} $txtPKey 1 Abort !endif ${EndIf} actSuccess: FunctionEnd