Support forum
wyDay blog
wyDay Home

Using TurboActivate with NSIS

Before you can do anything, you need to login to your LimeLM account (or sign up) and download the This zip contains the TurboActivate.dll & TurboActivate.exe along with source code examples.

Step-by-step walkthrough

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:

Using TurboActivate in your NSIS installer

Get NSIS 2.46 or newer

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.).

Step 1. Signup for LimeLM, download TurboActivate

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 and extract it anywhere. After you extract it you'll find 3 folders:

Step 2. Create a new product in LimeLM

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.

Adding your first product to LimeLM

Step 3. Download TurboActivate.datTurboActivate.dat and Version GUID

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.

Step 4. Add TurboActivate.dll to be included with your installer

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.

Step 5. Include the headers

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

Step 6. Set your version GUID

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'

Replace the "Paste GUID Here" string with the Version GUID string your copied from your version page.

Step 7. Adding the TurboActivate files to your installer

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.

  1. You need to "Reserve" the TurboActivate files so they extract quickly:
    ReserveFile "TurboActivate.dll"
    ReserveFile "TurboActivate.dat"
  2. You need to either create the ".onInit" function, or add the following lines to your existing ".onInit" function:
    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)."
        ; create the plugins folder
        ; extract the TurboActivate files to the plugns folder
        File /oname=$PLUGINSDIR\TurboActivate.dll "TurboActivate.dll"
        File /oname=$PLUGINSDIR\TurboActivate.dat "TurboActivate.dat"
  3. Your installer needs to extract the TurboActivate files to your "$INSTDIR" folder. Or, if you're not installing to that folder, you need to know how to modify the rest of the code to take advantage of TurboActivate:
    SetOutPath "$INSTDIR"
    File "TurboActivate.dll"
    File "TurboActivate.dat"
  4. Lastly, you uninstaller needs to delete the TurboActivate files. In this example we'll also deactivate your product before uninstalling:
    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"
        ; 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
        Delete "$INSTDIR\TurboActivate.dll"
        Delete "$INSTDIR\TurboActivate.dat"
        Delete "$INSTDIR\Uninstall.exe"
        RMDir "$INSTDIR"

Step 8. Add a product key entry page

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

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

    !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



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

    ${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."
          ${Case} 4 ; TA_E_INET
            MessageBox MB_OK|MB_ICONSTOP "Connection to the server failed."
          ${Case} 5 ; TA_E_INUSE
            MessageBox MB_OK|MB_ICONSTOP "The product key has already been activated with the maximum number of computers."
          ${Case} 6 ; TA_E_REVOKED
            MessageBox MB_OK|MB_ICONSTOP "The product key has been revoked."
          ${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."
          ${Case} 11 ; TA_E_COM
            MessageBox MB_OK|MB_ICONSTOP "CoInitializeEx failed."
          ${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."
            MessageBox MB_OK|MB_ICONSTOP "Failed to activate."



        !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