<< Click to Display Table of Contents >> Navigation: WinLicense > Protecting an application > Activation > Set everything up |
Set up the WinLicense database and PHP files in your webserver
1) Create a new database in your web server and a user for the database. This is commonly done from "cPanel" in your web server. Make sure that you allow all permits to that user to access to the database.
Notice that a possible firewall in your server might prevent connection to the database from any IP address. In that case, you can go to the "Remote MySQL" option (in your "cPanel") and add the IP address of the computer that will access the database (the one that runs WinLicense.exe)
2) Copy the files shipped in the "WinLicenseSDK/Activation/PHP" folder into your website (it has to be a path in your www or public_html folder, that is, a folder that can be accessed from a web browser)
3) Edit the file "main_settings.php" and set the different variables to allow access to the database (database name, user name, ....). Also set the location for the "ACTIVATION_APP" variable that will hold the location of the compiled "keygen" (in the /bin folder, we ship different compiled versions of our keygen source code for different platforms, you can just grab any of those compiled binaries or compile our source code for your platform)
4) Run "WinLicense.exe" and go to the "License Manager --> Database --> Select" and click on "Server database", after that WinLicense will restart and will prompt the login details to connect to your MySQL database that you have created in your server (in step "1)")
Add "Activation" to your (protected) application
5) Load the application that your are going to protect on WinLicense
6) Go to the "Activation" panel and select "Enable Activation"
7) In the "Web Server Settings" section, set the location (URL) of your website (where you host the WinLicense MySQL database and the necessary PHP files for activation/deactivation). If your website use the HTTPS protocol, you have to check the option "Is HTTPS".
8) In the "Activation URL", set the relative path where you copied the shipped "activate.php" file (from the above step "2)"). This is the relative path from your "www or public_html" folder.
8.1) If you want to make a quick test to check that everything is set up correctly in your web server, you can click on the right button ("...") on the Activation URL. It will prompt for an activation code and a hardware ID (you can enter a fake hardware ID here). After that, it will generate a link that you can enter in your web browser to simulate the activation process. The web browser will display the return value that was reported from your web server. The different return values are:
RESPONSE_ACTIVATION_OK (0)
RESPONSE_ERROR_KEY_NOT_FOUND (1)
RESPONSE_ERROR_MAX_SIMULTANEOUS_ACTIVATIONS_REACHED (2)
RESPONSE_ERROR_NO_MORE_ACTIVATIONS_ALLOWED (3)
RESPONSE_ERROR_NO_MORE_DEACTIVATIONS_ALLOWED (4)
RESPONSE_ERROR_DEVICE_NOT_FOUND (5)
RESPONSE_ERROR_WRONG_DATA_RECEIVED (6)
RESPONSE_ERROR_KEY_DISABLED_BY_SELLER (7)
RESPONSE_ERROR_KEY_EXPIRED (8)
RESPONSE_ERROR_NO_MORE_DIFFERENT_DEVICES_ALLOWED (9)
If everything is set up correctly and you entered a correct activation code, you can go to the WinLicense User Interface, "License Manager --> Manage Activations" and you should see that there is a new device that has been registered for the entered activation code.
9) In the "Deactivation URL", set the relative path where you copied the "deactivate.php" file. You can click on the right button (...) to simulate the deactivation process.
10) If you want to show a dialog, where your customer can enter the activation code, when your application is expired, etc. you have to check the option "Use embedded DLL to display your Activation dialog". This options requires an external DLL that will display a dialog where your customer can enter his activation code. You can create that DLL in Delphi, C/C++, etc. You can find source code examples and binaries in the "\WinLicenseSDK\Activation\ExampleActivationFromEmbeddedDLL" subfolder.
Enter the path to your DLL in the "DLL Name" edit box (you can use also predefined path constants) and select the callback/function in your DLL that displays the dialog in the "Function Handler" drop-down list.
When any trial/registration events occurs (like trial expired, license expired, license required to run, etc), WinLicense will call your "Function Handler" in your DLL to display your dialog, where the user can insert his activation code. Once the customer enters the activation code, WinLicense will do the following:
▪Get the current computer hardware ID and send that ID plus the activation code to your activation URL (activate.php)
▪If "activate.php" returns that the activation code is valid to be used, it will also return a license key locked to that specific machine. WinLicense will generate the license key into the system and will restart the application. When the application restarts, it will read the license key that was generated and will run your application in "registered" mode
▪If "activate.php" returns an error, WinLicense will display the error code and will prompt again to enter the activation code
If you plan to create your own DLL to show the activation dialog, we recommend that you first try with our shipped and compiled "ActivationDLL.dll" (under the "\WinLicenseSDK\Activation\ExampleActivationFromEmbeddedDLL\Delphi" subfolder), so you can see how it works.
11) In case that you don't plan to work with the "Activation Dialog" (from an external DLL), you can use the WinLicense SDK from inside your protected application (WLRegActivateSoftware). Using this approach, you can display a dialog from anyplace in your application where you ask for the activation code. Once entered the activation code, you have to call WLRegActivateSoftware to perform the activation process and obtain a license key from your web server. You can find an example in the "\WinLicenseSDK\Activation\ExampleActivationFromSDK" subfolder
12) Let's create a simple test:
▪Load your application on WinLicense and enable the "Activation" panel as described above
▪In the Activation panel, select the shipped DLL at "\WinLicenseSDK\Activation\ExampleActivationFromEmbeddedDLL\Delphi\ActivationDLL.dll" and select the "ActivationHandler" function (in the Function Handler drop-down list)
▪Go to the "Registration" panel, select "File License" (let's put "regkey.dat") and check the option "Application only runs when registered". This means that your application cannot run if there is not a license present
▪Protect your application
▪Run your protected application and you will see that the "Customized Dialog" MSG_ID_LICENSE_REQUIRED_RUN is displayed (this is because you set the option "Application only runs when registered"). After that, you can see that the dialog that prompts for an Activation Code is displayed (this dialog is from the embedded "ActivationDLL.dll")
▪Now, you need to enter an Activation Code. To do so, refer to the next section
Create an Activation Code from the "License Manager"
13) In the "License Manager" in WinLicense, add a new "Order" for your Software:
▪Click on the "Add Order" button
▪Select your software
▪Select a "Customer"
▪Go to the top "License" tab. Select "Activation" for the "Registration Type" option and click on "Generate"
▪Enter the license information (user name, company, etc) and if you want to add license restrictions (like expiration by days, executions, etc) and click OK
▪Now, you can see that the "Registration Information" panel is filled with information about the generated license and it also displays an "Activation Code". At this time, a new Activation entry has been added to the WinLicense database. Click OK to finish the generation of the new order
14) In the "License Manager", click on "Manage Activations". You can see all the activations that have already generated. You can find the one that you generated on the previous step "13)". You can copy the Activation Code (right click on the specific entry and select "Copy Activation" code)
15) In the test application (from step "12)"), enter the Activation Code that you just copied and click OK. If there are no errors connecting to your database, you will see that it will return success and a registration file is created (with the name that you set in the "Registration" panel in the "File License" option, i.e. "regkey.dat"). The application will restart and it will run as registered.
16) If you try to copy the generated "regkey.dat" into a different PC, you can see that your application displays the "Customized Dialog" MSG_ID_LICENSE_WRONG_HW_ID, saying that the license is locked to a different machine and your application will refuse to run.
Re-Check Activation on start up
If you want that your application connects to your web server (to the WinLicense database) each time that it starts, to check if the activation has been disabled by you (in case of banned/stolen license, etc), you can check the option "Recheck activation on start up". This option requires that you use the "Activation DLL" option to let WinLicense display your activation form when required. This is the way that it internally works:
▪Your application starts for the first time. WinLicense displays your activation dialog from your embedded DLL.
▪The user enters the Activation code and if it's verified correctly on your server (it requires internet connection), WinLicense will turn your application into "registered mode", without creating any physical license in the system (neither in file nor registry). At this point, WinLicense saves the entered activation code in the current system. At this point, if you go to the WinLicense database, you can see that the "activation counter" for that specific activation code has been increased by one.
▪The user launches the application again at a later time, WinLicense reads the activation code that was previously saved and sends it to your web server (internet connection is required)
▪If the activation code is still active (not disabled by you) and the Activation limit has not been achieved for the current activation code, your application will run into registered mode again. At this point, the "activation counter" for that specific activation code has been increased by one.
▪If the activation code has been disabled by you or the activation limit has been reached, WinLicense will display again the Activation dialog from your DLL, asking for a new Activation code.
This option can also be used as another method to restrict the number of executions for your application. Each time that your application is launched, the "Activation counter" will be increased in your database and when it matches the "Activation Limit" that was associated to the activation code, it will refuse to run. If you want to allow an unlimited number of executions for an activation code, in the "Activation Limit" field you can enter the value "65535" which will be considered as "UNLIMITED" by WinLicense.
Automate the generation of Activation Codes for your application
You can automatize the generation of licenses or activation codes from your payment processor. First of all, you have to be familiar with the SDK given by that your payment processor. After that, it should be easy to adapt the shipped PHP files to link it with your payment processor.
Under the "/WinLicenseSDK/Activation/PHP" folder you can find two PHP files that you can use to generate orders and licenses inside the WinLicense database. The "test_create_order_activation.php" and "test_create_order_file_license.php" will show you how to add a customer into the database and create a new order for him. The "test_create_order_activation.php" file shows you how to generate an activation code for your customer. The "test_create_order_file_license.php" file shows you how to generate a license file for your customer (skipping the whole activation process)
To test the above PHP files, adding a new customer and order from your web browser, you can call it as:
your_web_address.com/test_create_order_activation.php?user_first_name=Peter&user_last_name=Kron&user_email=pkron@peteremail.com&product_name=MySoftwareNameInWinLicense
(First of all, make sure that you set your specific database settings in the "main_settings.php" file)
If everything is set up correctly, you can go to the "License Manager" in WinLicense and see that a new order has been created for the specific software.
Example for Shareit
1) You can use the predefined "shareit_keygen.php" file (which should be almost the same for any other payment processor).
2) Now, you have to edit the file "settings.php" under the /payment_server/shareit folder. In the PAYMENT_SERVER_IP you can set the IP of your payment processor, so you make sure that the PHP file can only be called from that IP address
3) For each product that you sell, you have to add an entry in the "vendor_product" array. For example, you sell a product called "WinZZX" and you have created in the License Manager in WinLicense a Software called "WinZZX". From your payment processor, you get the ID for that product, for example, suppose that Shareit has assigned the value (ID) 16187 for that product. Now, in the "settings.php" file, you add the following line:
$vendor_product[16187] = "WinZZX"
Make sure that the name "WinZZX" matches with the name of the Software that you have created in the License Manager in WinLicense.
4) In the Shareit panel, point the URL in your server where "shareit_keygen.php" is located