This series of articles will show how to use tools available on the market to control licensing of plug-ins for Autodesk products. This is important to most commercial developers and if you are developing for the Autodesk Exchange Store, you noticed that no license system is provided, only a payment method. We’re not testing, validating or certifying the protection system and how hard it’s to (or not to) break it.
For this demonstration, we’ll use a .NET plug-in developed for AutoCAD, but the same idea can be applied to other .NET based APIs, like Revit and Inventor. Most of the code came from the samples available with the tool.
Here will be shown the Crypto Licensing for .NET, winning of the 2012 Members Choice of the Code Project development resource site. This tool is available for trial during 30 days and the prices start at $149 US dollars.
Between benefits:
- just a few lines of code added to any command on the plug-in, as will be shown on the sample;
- single .NET reference required that will enable all license features;
- supports obfuscation, although this feature is not included, but they offer a tool called Crypto Obsfucator for .NET starting at $149.
- support trial, mandatory feature for Autodesk Exchange Store, where every plug-in must immediately work after downloaded;
- serial or license code feature;
- authentication can be done online;
Of course, for AutoCAD environment, some cons:
- the solution is .NET based and therefore will only work for Windows platform;
- requires reference to Windows Form, which can affect AutoCAD console;
To test the Crypto solution, download it from here. After install it, launch it, the default new project will have the option to create a new validation key, like described on the image below.
The validation key will be used on the code below, which was based on the sample available at the C:Program Files (x86)LogicNP SoftwareCryptoLicensing For .Net 2012SamplesC#AppLicensing folder. On the code, the CryptoLicense object have a ValidationKey property that will receive the value obtained above.
The next step is to create a LicenseCode that will go embed on the code. On this case, let’s set it to run up to 5 days after first run. To create this code, select the number of days, as described on 1 at the image below. Then click on Generate, as shown on 2 and then finally get the code on 3.
Finally place the validation key and license code at the code, like shown at the sample code below. Compile and NETLOAD on AutoCAD.
using System; using System.Collections.Generic; using System.Linq; using System.Text; // Crypto licensing namespace using LogicNP.CryptoLicensing; // AutoCAD namespaces using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.EditorInput; namespace AutoCAD_Crypto { public class Commands { public static bool Licensed 
60; { get { // Create the object to check the license CryptoLicense license = new CryptoLicense(); // Get the validation key using Ctrl+K in the Generator UI. license.ValidationKey = ""; // The license will be loaded from/saved to the registry license.StorageMode = LicenseStorageMode.ToRegistry; // Load the license from the registry if (!license.Load()) { // When app runs for first time, the load will // fail, so specify an evaluation code.... // This license code was generated from the Generator // UI with a "Limit Usage Days To" setting to some days. license.LicenseCode = ""; // Save it so that it will get loaded // the next time app runs license.Save(); } // ShowEvaluationInfoDialog shows the dialog only // if the license specifies evaluation limits bool licensed = license.ShowEvaluationInfoDialog( "AutoCAD_Crypto", "http://www.companyname.com/buy"); // it is possible check if the application // still in evaluation mode using the following code if (license.IsEvaluationLicense()) { } // Be sure to call Dispose when done // using the CryptoLicense object. // The 'using' keywork is not a option // as this object do not implement IDisposable license.Dispose(); return licensed; } } [CommandMethod("licensedTestPlugin")] public static void CmdMyTestCommand() { if (!Licensed) return; // If is licensed, show a message Editor ed = Application.DocumentManager. MdiActiveDocument.Editor; ed.WriteMessage("nI'm working now"); } } }
Once we NETLOD and run the command, will show a warning like below. Notice that it still showing ‘30 days of trial’, but this is because I’m using the trial version of Crypton solution.
As the trial version do not allow generate other types of code, I will stop here, but if the user clicks on ‘Enter License’ button, it’ll prompt for another license key that can be generated like the before, but specifying another usage restriction.
The ‘Purchase’ button will open the URL specified on the code, which is the website where the user can buy the application.
Have used this solution before? Have used any other solution? Please share your experience, we can create an article on it.
Next article will discuss the IntelliProtector, as suggested on this comment.




Leave a Reply