public ActivationForm() { InitializeComponent(); try { // LexActivator.SetProductFile ("ABSOLUTE_PATH_OF_PRODUCT.DAT_FILE"); LexActivator.SetProductData("PASTE_CONTENT_OF_PRODUCT.DAT_FILE"); LexActivator.SetProductId("PASTE_PRODUCT_ID", LexActivator.PermissionFlags.LA_USER); // LexActivator.SetLicenseCallback(LicenseCallback); int status = LexActivator.IsLicenseGenuine(); if (status == LexStatusCodes.LA_OK || status == LexStatusCodes.LA_EXPIRED || status == LexStatusCodes.LA_SUSPENDED || status == LexStatusCodes.LA_GRACE_PERIOD_OVER) { uint expiryDate = LexActivator.GetLicenseExpiryDate(); int daysLeft = (int)(expiryDate - unixTimestamp()) / 86400; this.statusLabel.Text = "License genuinely activated! Activation Status: " + status.ToString(); this.activateBtn.Text = "Deactivate"; this.activateTrialBtn.Enabled = false; // Checking for software release update // LexActivator.CheckForReleaseUpdate("windows", "1.0.0", "stable", SoftwareReleaseUpdateCallback); return; } status = LexActivator.IsTrialGenuine(); if (status == LexStatusCodes.LA_OK) { uint trialExpiryDate = LexActivator.GetTrialExpiryDate(); int daysLeft = (int)(trialExpiryDate - unixTimestamp()) / 86400; this.statusLabel.Text = "Trial period! Days left:" + daysLeft.ToString(); this.activateTrialBtn.Enabled = false; } else if (status == LexStatusCodes.LA_TRIAL_EXPIRED) { this.statusLabel.Text = "Trial has expired!"; } else { this.statusLabel.Text = "Trial has not started or has been tampered: " + status.ToString(); } } catch (LexActivatorException ex) { this.statusLabel.Text = "Error code: " + ex.Code.ToString() + " Error message: " + ex.Message; } }
static void Main(string[] args) { try { Init(); LexActivator.SetLicenseCallback(LicenseCallback); int status = LexActivator.IsLicenseGenuine(); if (LexStatusCodes.LA_OK == status) { Console.WriteLine("License is genuinely activated!"); uint expiryDate = LexActivator.GetLicenseExpiryDate(); int daysLeft = (int)(expiryDate - DateTimeOffset.Now.ToUnixTimeSeconds()) / 86400; Console.WriteLine("Days left:" + daysLeft); // Checking for software release update // LexActivator.CheckForReleaseUpdate("windows", "1.0.0", "stable", SoftwareReleaseUpdateCallback); } else if (LexStatusCodes.LA_EXPIRED == status) { Console.WriteLine("License is genuinely activated but has expired!"); } else if (LexStatusCodes.LA_GRACE_PERIOD_OVER == status) { Console.WriteLine("License is genuinely activated but grace period is over!"); } else if (LexStatusCodes.LA_SUSPENDED == status) { Console.WriteLine("License is genuinely activated but has been suspended!"); } else { int trialStatus; trialStatus = LexActivator.IsTrialGenuine(); if (LexStatusCodes.LA_OK == trialStatus) { uint trialExpiryDate = LexActivator.GetTrialExpiryDate(); int daysLeft = (int)(trialExpiryDate - DateTimeOffset.Now.ToUnixTimeSeconds()) / 86400; Console.WriteLine("Trial days left: " + daysLeft); } else if (LexStatusCodes.LA_TRIAL_EXPIRED == trialStatus) { Console.WriteLine("Trial has expired!"); // Time to buy the product key and activate the app Activate(); } else { Console.WriteLine("Either trial has not started or has been tampered!"); // Activating the trial trialStatus = LexActivator.ActivateTrial(); // Ideally on a button click inside a dialog if (LexStatusCodes.LA_OK == trialStatus) { uint trialExpiryDate = LexActivator.GetTrialExpiryDate(); int daysLeft = (int)(trialExpiryDate - DateTimeOffset.Now.ToUnixTimeSeconds()) / 86400; Console.WriteLine("Trial days left: " + daysLeft); } else { // Trial was tampered or has expired Console.WriteLine("Trial activation failed: " + trialStatus); } } } } catch (LexActivatorException ex) { Console.WriteLine("Error code: " + ex.Code.ToString() + " Error message: " + ex.Message); } Console.WriteLine("Press any key to exit"); Console.ReadKey(); }
private LicenseInfo GetLicenseInfo() { lock (licenseInfoLock) { var licenseInfo = new LicenseInfo(); int status = 0; try { var sbLicenseKey = new StringBuilder(256); status = LexActivator.GetLicenseKey(sbLicenseKey, 256); if (status != LexActivator.StatusCodes.LA_OK) { return(null); } licenseInfo.LicenseKey = sbLicenseKey.ToString(); } catch { } try { var sbLicenseUserEmail = new StringBuilder(256); status = LexActivator.GetLicenseUserEmail(sbLicenseUserEmail, 256); if (status != LexActivator.StatusCodes.LA_OK) { return(null); } licenseInfo.LicenseUserEmail = sbLicenseUserEmail.ToString(); } catch { } try { var sbLicenseUserName = new StringBuilder(256); status = LexActivator.GetLicenseUserName(sbLicenseUserName, 256); if (status != LexActivator.StatusCodes.LA_OK) { return(null); } licenseInfo.LicenseUserName = sbLicenseUserName.ToString(); } catch { } try { var sbMaxAllowedIndexerRoleCount = new StringBuilder(256); status = LexActivator.GetLicenseMetadata("MaxAllowedIndexerRoleCount", sbMaxAllowedIndexerRoleCount, 256); if (status == LexActivator.StatusCodes.LA_OK) { if (int.TryParse(sbMaxAllowedIndexerRoleCount.ToString(), out int dummyMaxAllowedIndexerRoleCount)) { licenseInfo.MaxAllowedIndexerRoleCount = dummyMaxAllowedIndexerRoleCount; } } } catch { } for (int i = 1; i < 33; i++) { try { var sbIndexer = new StringBuilder(256); status = LexActivator.GetLicenseMetadata("Indexer" + i.ToString().PadLeft(2, '0'), sbIndexer, 256); if (status == LexActivator.StatusCodes.LA_OK) { licenseInfo.AddIndexer(sbIndexer.ToString()); } } catch { } } try { var sbFirstName = new StringBuilder(256); status = LexActivator.GetActivationMetadata("FirstName", sbFirstName, 256); if (status != LexActivator.StatusCodes.LA_OK) { return(null); } licenseInfo.FirstName = sbFirstName.ToString(); } catch { } try { var sbLastName = new StringBuilder(256); status = LexActivator.GetActivationMetadata("LastName", sbLastName, 256); if (status != LexActivator.StatusCodes.LA_OK) { return(null); } licenseInfo.LastName = sbLastName.ToString(); } catch { } try { var sbEMail = new StringBuilder(256); status = LexActivator.GetActivationMetadata("eMail", sbEMail, 256); if (status != LexActivator.StatusCodes.LA_OK) { return(null); } licenseInfo.EMail = sbEMail.ToString(); } catch { } try { var sbOrganization = new StringBuilder(256); status = LexActivator.GetActivationMetadata("Organization", sbOrganization, 256); if (status != LexActivator.StatusCodes.LA_OK) { return(null); } licenseInfo.Organization = sbOrganization.ToString(); } catch { } try { uint licenseExpiryDate = 0; status = LexActivator.GetLicenseExpiryDate(ref licenseExpiryDate); if (status != LexActivator.StatusCodes.LA_OK) { return(null); } var expireDate = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); var dueDate = expireDate.AddSeconds(licenseExpiryDate).ToLocalTime(); licenseInfo.LicenseExpiryDate = dueDate; } catch { } return(licenseInfo); } }