ICA connections using Powershell – Part 2

In part 1, I talked about the basics of using the ICA Client Object SDK (ICO SDK). In this second part, I’ll talk about modifying the appearance of your ICA connection using the ICO SDK. This includes:

  • Resolution
  • Color Depth
  • Fullscreen and Seamless Mode

Resolution

The resolution of the ICA connection is modified by setting two properties in your ICO SDK: DesiredHRES (horizontal resolution) and DesiredVRES (vertical resolution). By default the used resolution is 640×480. We already had the following code to make the ICA connection:

[System.Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Citrix\ICA Client\WfIcaLib.dll")
$ICA = New-Object WFICALib.ICAClientClass
$ICA.Address = "XASRV001"
$ICA.Username = "TestUser01"
$ICA.SetProp("Password","MyUsersPassword")
$ICA.Domain = "LAB"
$ICA.Application = ""
$ICA.Launch = $true
$ICA.OutputMode = [WFICALib.OutputMode]::OutputModeNormal
$ICA.Connect()

To define the resolution to 1024×768, we need to add these lines just before the Connect() method:

$ICA.DesiredHRes = 1024
$ICA.DesiredVRes = 768

Now, when running the script should look like this:

[System.Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Citrix\ICA Client\WfIcaLib.dll")
$ICA = New-Object WFICALib.ICAClientClass
$ICA.Address = "XASRV001"
$ICA.Username = "TestUser01"
$ICA.SetProp("Password","MyUsersPassword")
$ICA.Domain = "LAB"
$ICA.Application = ""
$ICA.Launch = $true
$ICA.OutputMode = [WFICALib.OutputMode]::OutputModeNormal
$ICA.DesiredHRes = 1024
$ICA.DesiredVRes = 768
$ICA.Connect()

Your ICA connection has a resolution of 1024×768 now. Sweet! But… The colors are probably still ugly. On to the next step.

Color Depth

The default color depth is 256 colors. Doesn’t really look pretty, right? The color depth in the ICO SDK can be set by modifying the DesiredColor property. The valid values are:

  • Color16
  • Color256
  • Color16bit
  • Color24bit

These values are of type “ICAColorDepth”, so if you want to set the color depth to 16bit you can use the following line before the Connect() method:

$ICA.DesiredColor = [WFICALib.ICAColorDepth]::Color16bit

So the complete source code would look like this:

[System.Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Citrix\ICA Client\WfIcaLib.dll")
$ICA = New-Object WFICALib.ICAClientClass
$ICA.Address = "XASRV001"
$ICA.Username = "TestUser01"
$ICA.SetProp("Password","MyUsersPassword")
$ICA.Domain = "LAB"
$ICA.Application = ""
$ICA.Launch = $true
$ICA.OutputMode = [WFICALib.OutputMode]::OutputModeNormal
$ICA.DesiredHRes = 1024
$ICA.DesiredVRes = 768
$ICA.DesiredColor = [WFICALib.ICAColorDepth]::Color16bit
$ICA.Connect()

Fullscreen and Seamless Mode

A windowed ICA connection may be suitable for some cases, but what if you want to start a desktop sessions full screen? Well, that’s actually quite easy. You need to set the DesiredHRes and DesiredVRes to the maximum value possible. That is, that maximum value of a 32bit integer (since these properties are Int32 types). You can define this in 2 ways: either defining an absolute number (2147483647) or using the type-maximum (using [System.Int32]::MaxValue).

$ICA.DesiredHRes = 2147483647
$ICA.DesiredVRes = 2147483647
# -- OR USING --
$ICA.DesiredHRes = [System.Int32]::MaxValue
$ICA.DesiredVRes = [System.Int32]::MaxValue

Using these values will launch your session full screen. But what about launching a published application? Simple, just define the “Application” property. For example, if you have published Notepad:

$ICA.Application = "Notepad"

This will connect to the published Notepad on the server which you defined in “Address”.

Note that this is the “Application name”, not the “Display name”. If you created Notepad as depicted, use “PubNotepad” as your “Application” property value.

Ok, let’s launch this published application by using this script:

[System.Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Citrix\ICA Client\WfIcaLib.dll")
$ICA = New-Object WFICALib.ICAClientClass
$ICA.Address = "XASRV001"
$ICA.Username = "TestUser01"
$ICA.SetProp("Password","MyUsersPassword")
$ICA.Domain = "LAB"
$ICA.Application = "Notepad"
$ICA.Launch = $true
$ICA.OutputMode = [WFICALib.OutputMode]::OutputModeNormal
$ICA.DesiredHRes = 800
$ICA.DesiredVRes = 600
$ICA.DesiredColor = [WFICALib.ICAColorDepth]::Color16bit
$ICA.Connect()

And your connection should look like this:

A windows ICA connection. But we actually want to launch this published application in seamless mode. Try using the “TWIMode” boolean property, this enables or disables seamless mode for the connection:

$ICA.TWIMode = $true

Putting it all together:

[System.Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Citrix\ICA Client\WfIcaLib.dll")
$ICA = New-Object WFICALib.ICAClientClass
$ICA.Address = "XASRV001"
$ICA.Username = "TestUser01"
$ICA.SetProp("Password","MyUsersPassword")
$ICA.Domain = "LAB"
$ICA.Application = "Notepad"
$ICA.Launch = $true
$ICA.OutputMode = [WFICALib.OutputMode]::OutputModeNormal
$ICA.DesiredHRes = 800
$ICA.DesiredVRes = 600
$ICA.DesiredColor = [WFICALib.ICAColorDepth]::Color16bit
$ICA.TWIMode = $true
$ICA.Connect()

Nice! A perfect seamless ICA connection.

Hope this post was usefull for you. Next time, I’ll talk about the ICO SDK events you can use.

One thought to “ICA connections using Powershell – Part 2”

Leave a Reply

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

Complete the following sum: * Time limit is exhausted. Please reload CAPTCHA.

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