[You can watch a video version of this guide here]
Following is a step by step procedure to protect an MS-Access application. Note that the steps below assume you have a QLM License Server already setup.
1. Launch QLM
2. Create a product from the “Define Product” tab or use the Demo 1.0 product if you are evaluating QLM.
3. Go to the "Protect your application tab":
- Page 1: Select the product to protect and the License Server
- Page 2: Select "VB6, VBA, ..."
- Page 3: Leave the default settings or customize the look & feel if needed
- Page 4: Select the folder where your Access application is located and click Save
- Page 5: Click Finish
4. Copy the following files to the folder where your MS-Access application is located:
- C:\Program Files\Soraco\QuickLicenseMgr\Redistrib\.net 2.0\QlmlicenseLib.dll
- C:\Program Files\Soraco\QuickLicenseMgr\Redistrib\.net 2.0\QlmLicenseLib.tlb
- C:\Program Files\Soraco\QuickLicenseMgr\Redistrib\.net 2.0\QlmCLRHost_x64.dll
- C:\Program Files\Soraco\QuickLicenseMgr\Redistrib\.net 2.0\QlmCLRHost_x86.dll
5. Copy the following files to a subfolder called "Net4" where your MS-Access application is located:
- C:\Program Files\Soraco\QuickLicenseMgr\Redistrib\.net 4.0\QlmlicenseLib.dll
- C:\Program Files\Soraco\QuickLicenseMgr\Redistrib\.net 4.0\QlmLicenseWizard.exe
6. Open your MS-Access application and click Alt-F11 to launch the VBA Editor.
7. Click Tools / Add References and add the following references:
- c:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.tlb
- c:\Windows\Microsoft.NET\Framework\v2.0.50727\mscoree.tlb
- QlmLicenseLib.tlb
8. Assuming your MS-Access application has a Form, add a Form_Open event as follows:
Private Sub Form_Open(Cancel As Integer)
QlmCheckLicense
End Sub
9. In the VBA editor, click Insert / Module and set the module name to CheckLicense.
10. Paste the following code in the CheckLicense module:
Dim homeDir As String
Dim lv As LicenseValidator
Dim settingsFile As String
Function QlmCheckLicense()
homeDir = CurrentProject.Path
' Update the filename below with the one that you generated via the Protect Your App Wizard
settingsFile = homeDir & "\Demo 1.0.lw.xml"
Set lv = New LicenseValidator
lv.InitializeLicense homeDir, settingsFile
'
' for debugging purposes / stepping through the code - remove the Stop when done.
'
StopOn Error GoTo PROC_ERR
Dim needsActivation As Boolean
Dim errorMsg As StringDim binding As ELicenseBinding
binding = ELicenseBinding_ComputerNameIf lv.ValidateLicenseAtStartupByBinding(binding, needsActivation, errorMsg) = False Then
If LaunchWizard = 4 Then
ExitApp
End If
If lv.ValidateLicenseAtStartupByBinding(binding, needsActivation, errorMsg) = False Then
ExitApp
End If
End IfExit Function
PROC_ERR:
MsgBox "Error: (" & Err.Number & ") " & Err.Description, vbCritical
Stop
ExitAppEnd Function
Private Sub ExitApp()
' Before shipping your app, uncomment the Close statement in the ExitApp Sub
' During development, you may want to comment it out to avoid getting locked out of your app'DoCmd.Quit
End SubPublic Function LaunchWizard() As Long
Dim args As String
args = args & " /settings " & """" & settingsFile & """"
args = args & " /computerID " & lv.fOSMachineName
#If VBA7 Then
Dim exitCode As LongPtr
#Else
Dim exitCode As Long
#End If
Dim wizardExe As String
wizardExe = homeDir & "\Net4\QlmLicenseWizard.exe"
If Dir(wizardExe) = "" Then
wizardExe = "C:\Program Files\Soraco\QuickLicenseMgr\QlmLicenseWizard.exe"
End If
exitCode = lv.LicenseObject.LaunchProcess(wizardExe, args, True, True)
LaunchWizard = exitCodeEnd Function
11. In the VBA editor, click Insert "Class Module"
12. Set the Class Module Name to: LicenseValidator
13. Paste the content of the LicenseValidator.cls file (this file was generated by the Protect Your application wizard) into the LicenseValidator class module.
This completes the integration. The next time you open your MS-Access form, the Form_Open event should get triggered and perform the license validation.
To generate a license key for testing purposes:
- Go to the Manage Keys tab.
- Click "Create Activation Key"
- Select the Product (Demo 1.0 for trials) and click Ok.
- Copy and Paste the generated Activation Key in the License Wizard launched when your MS-Access Application starts up and follow the steps in the wizard.
During development, if a license is not valid, the Excel workbook will still open. When ready, uncomment the Close statement in the ExitApp Sub.
Finally, do not forget to password protect your VBA code to protect it. To protect your VBA code:
- In the VBA Editor, click Toos / "YourProject" Properties
- Go to the Protection tab
- Check "Lock project for viewing"
- Enter a password / confirm password
- Click OK
Comments
0 comments
Article is closed for comments.