Remote Desktop Services session scripting

You can use FastTrack scripts to query information about the client executing a Remote Desktop Services session from the server-side, such as the client name and IP address.

You can also use a simple condition to detect, if a shared script is currently executing as a Remote Desktop Protocol (RDP) session or not, and take different actions based on this condition. For example in a logon script, the client IP address could be used to make correct printer or share mappings.

From the client side, you can query version information about the RDP client and you can start and control desktop sessions. This enables you to create launch menus, which can be a mix of RDP sessions, ICA sessions and locally installed applications. Such menus can be useful for building application launchers or Thin PCs.

A similar page for Citrix XenApp and XenDesktop is available here. Also, check the RDS Session Terminator Application, which uses the features shown on this page to compile a script into to an exe file that can logoff disconnected users by a Help Desk without administrative permissions.

Remote Desktop Services scripting

Remote Desktop Services sessions from the server-side

RDS Server menu When you use FastTrack scripts on the server-side, for example for Logon Scripts or application launchers, you can get the name and IP address of the remote client, the name of the executing published application (if not a full desktop session) and you can detect, if the script is actually running through an RDP session or not. This is extremely powerful information to have, because this means that you can differentiate your logon script and avoid unintended execution for remote users.

Under the "Remote Desktop Services Server" in the editor Engine Browser tree (see picture to the right), you will see that "RemoteSession", "ClientName", "ClientIP" and "ClientIPPart" are also present under "Citrix Server". This is because the intention is to provide transparency between RDP and ICA sessions with FastTrack scripts, because the desired logic is usually the same for both and with common functions and conditions, scripts will be shorter and simpler.

The ClientName function will return the name of the client executing the session regardless of RDP or ICA, whereas RdpClientName and IcaClientName will only work for one technology. The reason both are available is because "ClientName" makes sense in most cases and especially in common scripts like logon scripts, but for application launchers or similar, scripts are more readable when using an explicit function like RdpClientName.

The condition "RemoteSession" determines, if the executing script is running under an RDP or ICA session. If you want separate logic, there are two split conditions called "RdpSession" and "IcaSession" to determine, which is true, if any. In the simplest form, you can use the information to stop a logon script on ICA and RDP sessions:

If RemoteSession Then Exit


Using the client name

Another example is that the we can use the client name to determine, if the computer running the session is a computer in the domain or not, as part of a logon script. We can do this by asking the Active Directory, if a computer account exists with the same name and then we can react to this. In the example below, we kindly remind the user that the Codes of Conduct for use of remote sessions applies and then we log the information to the server event log. We could have taken more severe steps, such as simply logging off the session or we could also just log the information server-side.

If RemoteSession Then

  If Not ComputerExists [ClientName] Then

    LogEvent Remote Logon,External logon by [UserName] from client named [ClientName] from [ClientIP].

    ShowMessage You are connecting to the network from an external computer. Remember that codes of conduct applies!

  End If

End If

When an unknown client is detected, the warning is shown (see below) and an entry is logged in the server's event log.

Citrix remote warning

Citrix event logging

Determining client location

You can also retrieve the IP address of the executing client. This information is especially useful for connecting printers and shares. If you look at the Logon Script examples, you will find examples, where location is determined by the IP address. When using the IPAddress or IPAddressPart functions, these return the IP address of the physical machine. When using remote session, we want to do the same, but we want to do it based on the IP address of the executing client. To solve this problem, we can simply use the ClientIP and ClientIPPart functions instead. These will first try to detect an ICA or RDP session and return the client IP address. If the session is not a remote session at all, the IP address of the physical machine is returned. The net result is that we can in general simply replace the functions and they will work as intended in all scenarios.

Remote Desktop Services client

RDS client menu You can from the client-side use FastTrack scripts to query information about the installed version of the RDP client. You can also start and control RDP desktop sessions, the same way that you can do with ICA sessions. Please have a look under "Remote Desktop Services Client" in the Engine Browser tree in the editor (see picture to the right).

Using installed RDP client information

As the RDP client is by default installed with Windows, it does not make sense to check for installation status of the client. But it would be very relevant to check, if Windows XP machines have version 6.0 or newer installed, to make sure there is client support for RemoteApps. To avoid problems, we could simply ask the user to contact the HelpDesk, if they have an older version through the logon script:

If [RdpClientVersionMajor]<6 Then

  ShowErrorMessage Your PC cannot run server apps. Please contact the HelpDesk.

End If

If the end user has a version older than version 6.x, a warning is shown that the user must contact the HelpDesk:

RDP Menu

Starting sessions

You can start a desktop session either in a window or full-screen and you can query whether the session was successful or not. You can for example use this to build launch menus mixed between local applications and Remote Desktop and XenApp sessions. Have a look at the building a Thin PC page for an example of using a menu instead of starting Explorer.exe as the shell process.

The script below is a simple example, where first menu item starts the locally installed notepad. The second item starts a windowed desktop through an ICA session, the third item starts an RDP Remote Desktop and the fourth item starts notepad as a seamless Citrix XenApp server application. You can insert this example in the script editor by selecting "Remote Session Menu" in the "New Script" window.

If Not IcaClientInstalled Then

  ShowErrorMessage You do not have Citrix Receiver installed. Please contact the HelpDesk.

  Exit

End If

 

:Restart

Set Selection=[Menu Select item,Document|Notepad,Screen|Acme Server 1,Screen|Acme Server 2,Process|Acme App 1,Stop|Exit]

 

Switch [Var Selection]

  Case Notepad

    Run Notepad.exe

  Case Acme Server 1

    ShowIcaDesktop 192.168.1.8,sysadm,L5yEMnBNFTrmdsTg+MsErA==

  Case Acme Server 2

    ShowRemoteDesktop 192.168.1.3:443,sysadm,L5yEMnBNFTrmdsTg+MsErA==

  Case Acme App 1

    RunIcaApp 192.168.1.8:8080,Notepad,sysadm,L5yEMnBNFTrmdsTg+MsErA==

  Case Exit

    Exit

End Switch

 

Goto Restart


Citrix Menu

Using the ShowRemoteDesktop command will result in a window like the one below (picture is scaled to 50%). When the user closes the window, the script continues, and the menu is therefore shown again. The condition "LastRdpSessionFailed" can be used to detect problems connecting or executing the session.

Remote Desktop with FastTrack


Rating: 5 out of 5

"Use this as a replacement for VBScript and PowerShell"

"It's easy to include attractive GUI elements in FastTrack scripts, beyond the basic dialog boxes and text input that VBScript offers ... Another powerful feature is the ability to distribute scripts as Windows Installer (.msi) or standard .exe files. Although interesting in its own right, this ability results in a much more intriguing capability: to repackage -- or wrap -- software installers as .msi files without using snapshots. If you've ever created an .msi installer file from before-and-after system snapshots, for use with a software distribution system such as Group Policy or SCCM, then you know how hit-and-miss the results can be."

Read full review


Rating: 8 out of 10

"Faster than the rest"

"We found the FastTrack syntax to be more transparent and easier to learn than Microsoft's PowerShell – the editor in particular provided good support in this regard. the Script Editor offers a large number of options from the command set through to simple output of graphical elements, which cannot be achieved at all with PowerShell or other solutions or only with a significantly greater level of effort."

"Anyone wanting to tackle the many hurdles in everyday admin and especially anyone for whom logon scripts and client automation is a priority will benefit from the variety of functions offered by FastTrack."

Review in English      Review in German