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