Since version 10.x of the ICA Client, Citrix has shipped the ICA Client Object (ICO) SDK with the installation. This allows developers to control the ICA Client. Writing managed code using ICO is a breeze (my ICAConnect tool is using it), but you can easily write Powershell scripts which leverage the SDK.
The ICOSDK is accessible by using a DLL called “WfIcaLib.dll”, which is located in your ICA Client (or Citrix Receiver) installation directory (default is “%ProgramFiles%\Citrix\ICA Client” on 32bit platforms and “%ProgramFiles(x86)%\Citrix\ICA Client” on 64bit platforms). Now let’s have some fun with the ICO SDK using Powershell.
First of all, we need to start up Powershell to start working. Since the ICO SDK is a 32bit DLL, we need to start Powershell in x86 mode (this is only valid if you’re using a 64bit Operating System). Press Start > Accessories > Windows PowerShell > Windows PowerShell (x86). Note that it should display “Windows PowerShell (x86)” in the PowerShell window.
Ok, now it’s time to load the ICO SDK library into Powershell. This can be done by executing the following command:
[System.Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Citrix\ICA Client\WfIcaLib.dll")
Note that I’m using a 64bit Operating System, so I’m pointing to “Program Files (x86)”, if you’re using a 32bit Operating System, you should point to “Program Files”. Now Powershell should display something like this:
GAC Version Location --- ------- -------- False v2.0.50727 C:\Program Files (x86)\Citrix\ICA Client\WfIcaLib.dll
Now we can start using the library. First of all, we need to create the ICAClienClass Object.
$ICA = New-Object WFICALib.ICAClientClass
All methods and properties are now available through the $ICA object. Next, we need to define some properties:
This is the address of the Citrix server you’re connecting to
The published application to connect to (if this is left empty, the ICA client will connect to the server’s desktop)
The user under which you want to connect
The domain for the user
This property tells the ICO SDK to launch a new session, this is a boolean (true or false) property
The way that the actual ICA Client is displayed on screen
Note that I left out the Password property. This is because there is no “real” password property to be set which defines the password to be used. I will discuss this later on.
The following commands will set these properties:
$ICA.Address = "XASRV001" $ICA.Application = "" # Connect to the server desktop $ICA.Username = "TestUser01" $ICA.Domain = "LAB" $ICA.Launch = $true $ICA.OutputMode = [WFICALib.OutputMode]::OutputModeNormal # Valid OutputModes: OutputModeNonHeadless, OutputModeNormal, OutputModeRenderless, OutputModeRenderless
Setting the password for the ICA connection can’t be done through a property, instead you will have to use the SetProp() method:
Ok, now that all properties have been set, we can make the connection to the defined server. This can be done by using the Connect() method:
This should start the ICA client on your machine and connect to the server. Note that after you enter the command, it could take a few seconds before the ICA connection pops up. If no ICA connection is shown, verify that the OutputMode is set to OutputModeNormal and that the Launch property is set to true.
In a default XenApp installation, the server desktop is not enabled by default, so you could receive the following error:
This can easily be solved by setting a Citrix User Policy. Define a policy in your AppCenter and set a user policy: ICA > Desktop Launches > Set to Allowed.
To sum up the complete script:
[System.Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Citrix\ICA Client\WfIcaLib.dll") $ICA = New-Object WFICALib.ICAClientClass $ICA.Address = "XASRV001" $ICA.Application = "" $ICA.Username = "TestUser01" $ICA.SetProp("Password","MyUsersPassword") $ICA.Domain = "LAB" $ICA.Launch = $true $ICA.OutputMode = [WFICALib.OutputMode]::OutputModeNormal $ICA.Connect()
Easy as that. Hope you found this post usefull and this helps you writing scripts using the ICO SDK. In my next post, I’ll talk about ways to change the session behaviour and appearance.