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:

  1. Pass the license key in to Keyman Engine and get activation request binary data in response
  2. Send this activation request binary data to the Tavultesoft activation server and receive activation response binary data in response
  3. 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 w
ith 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

ActivatedState = km.GetProductActivationInfo(ProductID, 1)
IF ActivatedState = 0
Categories: Using Keyman Desktop

0 thoughts on “Activating Keyman Desktop with Windows Script”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts

Amharic

Mitigation for Keyman, Windows 10 1803, and Amharic, Tigrinya and Sinhala issue

Background It recently came to our attention that under Windows 10 1803 and Windows 10 1809, Keyman keyboards simply do not work when associated with Amharic or Sinhala languages, and sometimes do not work with Read more…

Developing Keyman

How to send feedback to Microsoft for issues that impact Keyman

We report all issues in Windows that impact Keyman to Microsoft. If a particular issue impacts you, it is very helpful to “upvote” the issue or add further comments about the issue in the Feedback Read more…

Developing Keyman

Keyman is now free and open source

SIL International is very pleased to announce that Keyman is now completely free and open source! Today, 23 August 2017, we released free versions of the existing Keyman products on the Keyman website, and have Read more…