Software Licensing and Protection Business Discussion For those concerned with the business aspects of licensing and protection and with learning how other individuals are thinking about licensing and protection strategies
InishTech Support Forums > Software Licensing and Protection Business Discussion > Activate a license key from the command-line Login to add this as a favourite.
User avatar
Member
Member
jeremyluerkens - 2/17/2011 7:19:57 PM
   
Activate a license key from the command-line

I have a customer who wants to activate a license using a script from the command-line. Can this be done using LicAdmin, PowerShell or some other method?


User avatar
InishTech Dev
InishTech Dev
RBartelink - 2/17/2011 11:14:40 PM
   
RE:Activate a license key from the command-line

 Hi Jeremy,

A set of PS tasks and a provider is on the list but not delivered at present. LicAdmin doesnt offer a set of commandline options around this.

I know a number of customers have addressed this by building adding Installer classes into the hierarchy and by building small utilities in C#, but I  guess that's down to the fact that most devs find it hard to put down the C# golden hammer!

I cant think of any reason why a PS script with a New-Object or two wouldnt work.

The snippets in http://codepaste.net/list/user/inishtech%20support may help you do what you need.

If you get it done before I do, paste it up here!

--Ruben


User avatar
InishTech Dev
InishTech Dev
RBartelink - 2/18/2011 12:38:53 AM
   
RE:Activate a license key from the command-line

OK, I couldnt stop myself :D

Firstly, lest there be any confusion, this is not an official product release. While there's no rocket science here, this is not a core product scenario so we can't guarantee not to break it.

http://codepaste.net/xcnqqn has a snippet that does a normal online activation (without the dialog)

Unfortunately, things are messier than one'd hope as PowerShell wants to invoke directly against the object rather than taking just the interface it gets given when a method returns. Ordinarily this doesnt make much difference, but as the implementation details of our object model are obfuscated, one needs to use this trick from Powershell MVP Oisin Grehan to 'cast it back'. I've created a backup copy of get-interface at http://codepaste.net/rue9am

As mentioned at the start of this conversation, we have medium term plans to release a PS module to generate tasks and a provider to encapsulate core automation scenarios against the SLP Runtime APIs a a core supported part of our product. Another idea would be to have a PowerGUI PowerPack around standard functionality offer an alternative to the LicAdmin tool. With unlimited time, one'd use WPK to do a non-PowerGUI based UI too. I'm not in a position to map that to any timeline worth taking any form of dependency on.

I'll be interested to see whether you're crazy enough to mess with it in its current form!

--Ruben


User avatar
Member
Member
richardb - 2/9/2012 9:24:38 AM
   
RE:Activate a license key from the command-line

Hi Ruben,

I needed to do something similar and came across this post. Thanks for the info.

There is another way to invoke the SLP Runtime APIs that doesn't require the get-interface code snippet - you can just use reflection (as suggested on the workarounds tab of the original bug reported to Microsoft). I found this a bit easier to use as it doesn't depend on any external scripts.

Here's the code for doing the same thing via reflection:

# Your variables

$runtimeDir="$env:ProgramFiles\Inishtech SLP Code Protector"
$productName = "Product"
$productVersion = "1.0"
$shortCode = "abc12"
$activationKey="29KV3-E4T9M-WDTTD-KNVZB-YUVZZ"

# Load assembly and get methods via reflection. CreateActivationClient is overloaded so need to specify argument types

add-type -path "$runtimeDir\Microsoft.Licensing.Runtime2.0.DLL"
$createActivationClientMethod = [Microsoft.Licensing.ISLMActivation].GetMethod("CreateActivationClient", [System.Type[]]@([System.String],[System.String]))
$activateMethod = [Microsoft.Licensing.IActivationClient].GetMethod("Activate")

# Run the commands

$r = new-object Microsoft.Licensing.SLMRuntime $shortCode
$a = $r.Activation
$ac = $createActivationClientMethod.Invoke($a, @($productName, $productVersion))
$activateMethod.Invoke($ac, @($activationKey, ""))

I needed to install a license file using PowerShell. Here's the script for that:

# Your variables

$runtimeDir="$env:ProgramFiles\Inishtech SLP Code Protector"
$shortCode = "abc12"
$licFilePath = "C:\License\SLP_29KV3-E4T9M-WDTTD-KNVZB-YUVZZ.bin"

# Load assembly and get methods via reflection. OpenLicense is overloaded so need to specify argument types

add-type -path "$runtimeDir\Microsoft.Licensing.Runtime2.0.DLL"
$openLicenseMethod = [Microsoft.Licensing.ISLMLicenses].GetMethod("OpenLicense", [System.Type[]]@([System.String]))
$installLicenseMethod = [Microsoft.Licensing.ISLMLicenses].GetMethod("InstallLicense")

# Run the commands

$runtime = new-object Microsoft.Licensing.SLMRuntime $shortCode
$license = $openLicenseMethod.Invoke($runtime.Licenses, $licFilePath )
$installLicenseMethod.Invoke($runtime.Licenses, $license)

Hope this helps,

Richard


User avatar
Site admin
Site admin
RBartelink - 2/9/2012 12:27:16 PM
   
RE:Activate a license key from the command-line

Wow! Thanks for posting and congrats for working all those things out - that's definitely much cleaner. To be honest I hadn't looked at the original Connect bug and went straight to Oisin's approach and am almost ashamed to have left the post up here. Thankfully the thread now has a happy ending!

/mewonders whether my Payette V2 book covers this (or whether I skipped over it in V1), and whether PS V3 allow it directly as it uses the DLR under the covers...

--Ruben


1

10 user(s) on-line: 0 registered and 10 guest(s)

  • Sticky
  • Locked sticky
  • Hot sticky
  • Hot locked sticky
  • Thread
  • Hot thread
  • Locked thread