Using the ThinApp SDK from PowerShell

On August 19th 2010 the long awaited ThinApp SDK became available.It allows you to programmatically interact with your ThinApp packages.  The SDK package is foreseen to be used with Visual Studio, as can be deduced from the  included merge module called ThinAppSDK.msm. The samples that come with the SDK unfortunately only show the use of the SDK with C++ and VBScript. But with a bit of fiddling it’s quite easy to use the APIs from your PowerShell environment.

This post will show you:

  • how to set up the SDK for use from PowerShell
  • some usage examples from PowerShell.

Prepare the environment

The SDK package doesn’t contain a DLL with a manifest so we can’t use the LoadFile method to load the DLL into memory. But the ThinApp SDK has foreseen this.

First make sure you have the ThinAppSDK.dll and ThinAppSDKSrvr.exe files together in a directory.

Then register the DLL with the regsvr32 command. On a Windows client that has UAC enabled make sure you run regsvr32 from an elevated command prompt (run as administrator) !


Thanks to Greg Geldorp, the VMware Engineer that owns the ThinApp SDK, we know how the DLL gets loaded on a 64-bit client.

I quote from his reply in this thread.

“ThinAppSDK.dll is the DLL that implements the ThinApp SDK objects like ThinApp.Management. It is a 32-bit DLL, if you create a ThinApp.Management object from a 32-bit process Windows will load ThinAppSDK.dll into that process (if the DLL was registered correctly with regsvr32). However, it’s not possible to load a 32-bit DLL into a 64-bit process. So if you try to create a ThinApp.Management object from a 64-bit process, ThinAppSDK.dll cannot be loaded directly into that process.
That’s where ThinAppSDKSrvr.exe comes in. Windows will detect this situation and will automatically launch ThinAppSDKSrvr.exe. Since ThinAppSDKSrvr.exe is a 32-bit application, it can load ThinAppSDK.dll just fine. Windows will then “forward” ThinApp SDK calls (e.g. the GetThinAppType method call) from the 64-bit process to ThinAppSDKSrvr.exe, which will in turn forward it to ThinAppSDK.dll. The result will be passed back from ThinAppSDK.dll to ThinAppSDKSrvr.exe via Windows to the 64-bit application.”

You can always verify, for example with MSInfo32, that the DLL has been loaded.

What follows was tested on Windows XP Pro Sp3 32-bit and on Windows 7 64-bit.

How to use the SDK

First steps

All the following examples are based on a ThinApped version I made of XmlPad3, my favorite ‘free’ XML editor.

Let’s start with something simple.

The following lines will take an EXE produced by the ThinApp build process and determine the ThinApp type of file.

The result of the this simple script is not world-shocking but at least it show that we can interact with the ThinApp package.

From the VMware ThinApp SDK API Reference Guide, that is part of the SDK, we learn that this file is the main data container.

Let’s take another entry point of the package. In this case the cmd.exe entry point.

And we learn that this is a shortcut, or entry point, but not a container.

A bit more advanced script

Time to move on to a somewhat more advanced script.

With the SDK there are 2 samples and one of these is a script that lists subfolders and files for a specific path in the package.

This script is a loose emulation of the original.

A run of this script produces something like this:

Conclusion

The ThinApp SDK offers even for the PowerShell adept easy access to his ThinApp packages.  Another small step towards the complete automation of your ‘virtual’ environment.

4 Comments

    Laurensius

    Good article on ThinApp SDK. Just wondering if using SDK and powershell we can modify ThinApp executable? for example I’d like to change location of the sandbox and I no longer have the project files to change it in package.ini. Thank you.

      LucD

      @Laurensius, you can’t change the package itself, the SDK is mostly read-only.
      But you can set an environment variable to change the location (see Chap 6 of the ThinApp User’s Manual).
      Something like this

      $ThinAppPackage = "\\share\app\app.exe"
      $thinMgmt = New-Object -ComObject ThinApp.Management
      $package = $thinMgmt.OpenPackage($ThinAppPackage)
      $options = $package.GetOptions()
      $name = ($options | where {$_.Name -eq "InventoryName"}).Value
      cd env:
      New-Item -Name ($name + "_SANDBOX_DIR") -Value "C:\Sandbox"
      cd c:\
      Invoke-Item $ThinAppPackage

Leave a Reply

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

*
*

Buy the Book