Last active
February 18, 2016 21:15
-
-
Save ScottDeLuzio/9b6f2dd59f7e2b0f40f9 to your computer and use it in GitHub Desktop.
Software Licensing for Excel Add-In Activate License
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Sub httpRequestActivate() | |
| 'Run the httpRequestCheck to see if the license has used up all of the activations it had available. | |
| 'If it has we add in_use to cell A5 so that we can avoid allowing the license to be activated on more computers than our license allows. | |
| 'Note after the first activation, the license will return as valid before the end of the license expiration even if it has been deactivated so we need to check for remaining activations this way as well. | |
| httpRequestCheck | |
| With ThisWorkbook.Worksheets("Sheet1").Range("A1") | |
| If .Cells(4, 1).Value = 0 Then | |
| 'Cells(4, 1).Value is the number of activations remaining. In my case there will only be 1 or 0 but even if you allow more than one activation, 0 is where we should stop allowing it to be activated. | |
| 'This indicates that the license is in use on as many computers as the license will allow. We will check for this later. | |
| .Cells(5, 1).Value = "in_use" | |
| Else | |
| Dim oRequest As Object | |
| Const cUrl As String = "https://yoursite.com/?edd_action=activate_license&item_name=Name of the Download Product&license=" | |
| URL = cUrl & ThisWorkbook.Worksheets("Sheet1").Range("A1").Value | |
| Set oRequest = CreateObject("WinHttp.WinHttpRequest.5.1") | |
| oRequest.Open "GET", URL | |
| oRequest.Send | |
| 'When activating for the first time we need to activate the license and then use it, so we're basically sending the request twice. | |
| 'This step isn't necessary after the initial activation, so I suppose a check could be added to remove the redundancy. | |
| oRequest.Open "GET", URL | |
| oRequest.Send | |
| ThisWorkbook.Worksheets("Sheet1").Range("A2:A5").ClearContents | |
| ThisWorkbook.Worksheets("Sheet1").Range("A2").Value = oRequest.ResponseText | |
| ThisWorkbook.Worksheets("Sheet1").Range("A3").Formula = "=IF(MID($A$2,FIND(""license"",$A$2,1)+10,8)=""inactive"",""inactive"",IF(MID($A$2,FIND(""license"",$A$2,1)+10,5)=""valid"",""valid"",IF(MID($A$2,FIND(""license"",$A$2,1)+10,7)=""invalid"",""invalid"","""")))" | |
| ThisWorkbook.Worksheets("Sheet1").Range("A4").Formula = "=MID($A$2,FIND(""activations_left"",$A$2,1)+18,1)" | |
| End If | |
| End With | |
| End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment