Keyman Desktop includes a comprehensive API that allows you to control nearly every aspect of its behaviour. Today I’d like to focus on one small method of automating Keyman Desktop, that is, activating Keyman Desktop via script.
The activation process requires three steps:
- Pass the license key in to Keyman Engine and get activation request binary data in response
- Send this activation request binary data to the Tavultesoft activation server and receive activation response binary data in response
- Pass the activation response binary data to Keyman Engine to complete activation
This can be done neatly with Windows Script Host. This script could be used in a number of scenarios, including Windows Installer or Active Directory scripts. Error management is left up to the Keyman Engine and XMLHTTPRequest objects, and any errors will abort the script.
This script does not check if Keyman Desktop is already activated. That can easily be added using the GetProductActivationInfo function in ITavultesoftKeymanScript; there is no harm in reactivating but obviously you can save a call to the Tavultesoft activation server if you don’t need to reactivate.
The script must run in x86 context, so on Windows x64 hosts, make sure you use the cscript.exe or wscript.exe script host from the SYSWOW64 folder.
If you run the script with elevated privileges, then the activation will apply for all users; otherwise the activation will only apply for the current user.
‘ =======================================================================
‘
‘ ActivationScript.vbs.
‘
‘ (C) 2012 Tavultesoft Pty Ltd
‘
‘ Author: Marc Durdin
‘ Version: 1.0
‘ Date: 27 Feb 2012
‘
‘ For support with this script, please contact
‘ Tavultesoft Support <support@tavultesoft.com>
‘
‘ This script activates the product specified below with the license
‘ details embedded in this script.
‘
‘ The script must run in x86 context, not x64 context.
‘
‘ The script can be embedded in an .msi file, for example with a
‘ WiX custom action, wrap the code in a function called Activate()
‘ and add the following fragment to your .wxs source file:
‘
‘ <Binary Id=”ActivationScript.vbs” SourceFile=”ActivationScript.vbs” />
‘
‘ <CustomAction BinaryKey=”ActivationScript.vbs” Execute=”deferred”
‘ Id=”Activation” HideTarget=”yes”
‘ Impersonate=”no” Return=”check”
‘ VBScriptCall=”Activate” Win64=”no” />
‘
‘ <InstallExecuteSequence>
‘ <Custom Action=”Activation” Before=”InstallFinalize” />
‘ </InstallExecuteSequence>
‘
‘ =======================================================================
dim LicenseNumber, ProductID
‘ ================================
‘ Start of user-definable settings
‘ ================================
‘
‘ LicenseNumber – the license number you have been provided with by Tavultesoft
‘
LicenseNumber = “1234-5678-ABCD-EFGH-IJKL” ‘ This is not a valid license number!
‘
‘ ProductID:
‘ Keyman Desktop Pro 8.0 = 12
‘ Keyman Desktop Light 8.0 = 13
‘ Keyman Developer 8.0 = 14
‘ Other product IDs can be found in the registry when the product is installed,
‘ in HKEY_LOCAL_MACHINESoftwareTavultesoftKeyman Engine8.0
‘ Installed Products[productname]product id
‘
ProductID = 12
‘ ==============================
‘ End of user-definable settings
‘ ==============================
dim kmcom, kmcom2
dim ActivationRequest, ActivationResponse, XMLHttpRequest, ActivationURL
‘ ========================================================================
‘ Create Tavultesoft Keyman objects. We need both because we are using
‘ VBScript which cannot access some of the activation functions in the
‘ IKeymanProduct interface and so must use the ITavultesoftKeymanScript
‘ alternatives
‘ ========================================================================
Set kmcom = CreateObject(“kmcomapi.TavultesoftKeyman”)
Set kmcom2 = CreateObject(“kmcomapi.TavultesoftKeymanScript”)
‘ ========================================================================
‘ Generate an activation request blob
‘ ========================================================================
ActivationRequest = kmcom2.GetProductActivationRequest(ProductID, LicenseNumber)
‘ ========================================================================
‘ Send the activation request blob to the Tavultesoft secure server for activation
‘ For proxy, see: http://msdn.microsoft.com/en-us/library/ms760236%28v=vs.85%29.aspx
‘ ========================================================================
ActivationURL = “https://secure.tavultesoft.com/prog/70/activation.php”
Set XMLHTTPRequest = CreateObject(“MSXML2.ServerXMLHTTP.6.0”)
XMLHTTPRequest.open “POST”, ActivationURL, FALSE
XMLHTTPRequest.setRequestHeader “Content-Type”, “application/x-www-form-urlencoded”
XMLHTTPRequest.send “ActivationRequestBlob=”+ActivationRequest
‘ ========================================================================
‘ Collect the activation response blob from the response and pass it into the
‘ kmcom IKeymanProduct.Activate function to complete the activation. Activation will
‘ be per-user for a local user security context, or per-machine for an elevated
‘ security context.
‘ ========================================================================
ActivationResponse = XMLHTTPRequest.responseText
kmcom.Products.ItemsByProductID(ProductID).Activate(ActivationResponse)
‘ EOF
IF ActivatedState = 0
0 thoughts on “Activating Keyman Desktop with Windows Script”