Powershell Script to launch one or more Published Applications from Storefront 2.x

by Stan Czerno February 1, 2015 03:36 CST

NOTE: This script does not work with Storefont v3, click here for the updated script.

In a previous post, I shared a PowerShell script to launch a Published App from one or more servers. I originally wrote this script because one of my lab XenApp 6.5 servers would not launch a Published Application. When I investigated what the issue was I was unable to determine the cause. The IMA Service was started, ICA was listening and responding, there was no load issues, etc, etc. This server was basically healthy. 

I eventually got this server running again by removing it from the farm and re-joining it. As it turns out, there was an easier fix, as I found out last week. I tried launching an app that was only published from this server, and again, failure. But wait, my script was not alerting me to any errors, Published Applications from the script were launching from this server. My Powershell Script to monitor a Citrix XenApp Farm's Health was reporting all healthy.

What I determined was, the Server had Blue Screened due to a driver used for mounting ISOs, which was SlySoft's Virtual CloneDrive. When the XenApp Server recovered, there was an error in the Application Event Log about the IMA Service. The Service could not connect to the Data Store (MSSQL), but it Started. I had never noticed this before so I did not troubleshoot IMA. Normally if the IMA Service cannot connect to the Data Store it does not start. I decided to just restart the IMA Service and see what happens. The Service started fine, connected to the Data Store (MSSQL) and the Application launched. So much for monitoring the IMA Service (I need to work on this, but IMA is dead, so I probably will not).

I surmised that directly launching an Application from a XenApp Server would not query the IMA and would not encounter an issue if the IMA service was screwed up. So, back to the drawing board on monitoring that an Application actually launches.

So I took to Google again to see what else I could find. I found this blog entry at Citrix; Automating the launch of HDX sessions through StoreFront (and NetScaler Gateway integrated with StoreFront). The script emulates a user utilizing a Internet Explorer to connect to StoreFront and launch a Published Application.

As usual, I took it to the next level. I added more feedback and logging as well as detecting errors and firing off an email if an error is detected. I also added logging how long it takes to launch the session, just like my previous script did.

Just like my previous script, this is meant to run as a Scheduled Task using a test user to launch one or more Published Applications (or Desktops). I left my ailing server in the error state while testing this script and I was alerted that the Published Application would not launch. 

I schedule the script to run daily, once per hour, between 6AM and 6PM. If there is an error, I get an email with a summary of the issue.

Here are the requirements for the script:


  • Citrix Receiver installed in the default location.
  • Must be launched from an Elevated Administrator console of PowerShell x86. The 64 Bit Powershell will not work since the script is using Citrix Receiver, which is 32 bit, to verify a launch and log off the session.
  • No other sessions should be connected/running before running the script. Any Receiver processes will be killed, so existing sessions will be disconnected.
  • SiteURL should be part of the Intranet Zone or Trusted Site zone, set at Medium-Low security, in order to be able to download AND launch the ICA file without interaction. This can be done manually or via a GPO if this is not already the case.
  • StoreFront 2.0 or higher or NetScaler Gateway, version 9.3 or higher.
  • Changes in web.config under C:\inetpub\wwwroot\Citrix\<storename>Web\: autoLaunchDesktop to false, pluginAssistant to false.
  • Currently works for desktops or already subscribed apps only. 
    • You can auto subscribe users to apps by setting "KEYWORDS:Auto" in the published app's description or make sure the apps have been subscribed to manually.
  • This script does not support AppController at this time.
  • In order for the script to interact with the ICO, it requires the following to be set in the registry:
    • x64: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Citrix\ICA Client\CCM
    • AllowLiveMonitoring REG_DWORD 1
    • AllowSimulationAPI REG_DWORD 1

Create some Apps to use with the Script
The first thing you should do, before scheduling the task, is to publish an application (or Desktop) from each server and assign it to your test user. What I mean by that is; if you have five servers, you will need to publish the App or Desktop five times, one for each server. I am not testing load balancing, I am testing to make sure each server launches the application correctly.

I chose Task Manager, but it can be any application, such as Command Prompt. The more lightweight the application the better, you do not want to put extra strain on your servers.

You can also use a Published Desktop but Desktops are more resource intensive and take a little longer to launch since it initializes the Explorer shell. With this in mind, you may need to extend the wait time for the Log off command by adding -TimeToWaitForLogoff to the command line. By default this is set to 15 seconds and a Desktop may not load within 15 seconds. I have noticed that using a Desktop can be problematic. It is not so much an issue with the Server but with CDViewer on the client. So I recommend using Task Manager or Command Prompt for the test.

Subscribe to Apps
The Apps need to be visible in order for the Script to launch them. You will need to log in to Storefront, as the Test User, manually and subscribed to the Apps. Alternatively, you can auto subscribe the Apps by setting "KEYWORDS:Auto" in the published app's description.

Schedule the Task
My Scheduled Task's Action looks like this:


Add arguments: 
-executionpolicy bypass -file c:\CitrixScript\SFLauncher2.ps1 -SiteURL "https://citrix.domain.com" -UserName "domaain\TestUser" -Password "TestUserPassword" -smtpServer "smtp.server.domain" -emailFrom "XenAppMon@domain.com" -emailTo "email@domain.com" -LogFilePath C:\CitrixScript -LogFileName SFLauncher.log "App1" "App2"

Start in: 

Security options:
The user account needs to be an administrator on the client so PowerShell can be elevated. This does not need to be the Test User.
Use the option "Run whether user is logged on or not" and "Run with highest privileges".

Command Line Notes:
The Application(s) to be launched need to be at the end of the command line, separated by a space, like this: "App Server1" "App Server2"

Test from a Command Prompt:
If you want to test before Scheduling, open a Command Prompt as an Administrator (right click and choose "Run as Administrator")
To test the script, here is a sample command line:
%SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -file c:\CitrixScript\SFLauncher2.ps1 -SiteURL "https://citrix.domain.com" -UserName "domaain\TestUser" -Password "TestUserPassword" -smtpServer "smtp.server.domain" -emailFrom "XenAppMon@domain.com" -emailTo "email@domain.com" -LogFilePath C:\CitrixScript -LogFileName SFLauncher.log "App Server1" "App Server2"

Here is a Screenshot of what the script looks like while it is running:

I have tested the script with Internet Explorer 11 and Citrix Receiver 14.1 on Windows 7. I have also tested it on Windows 10 Preview with Citrix Receiver 14.2.

Here is the script:

Please let me know what you think, and if you have a better way of doing this, in the comments section.

SFLauncher2.ps1.txt (36.4KB)

Tags: , , , , ,

Catergories: Citrix | Receiver | Storefront | XenApp | Powershell

Comments (13) -

Jerry Moore
March 26, 2015 15:51 CST

This is a great script. Is there any way to get this to work with web interface 5.4? Thanks.

Stan Czerno
March 27, 2015 02:40 CST

Not sure about WI 5.4, I will see what I can come up with.

Jamey Lanzalaco
March 27, 2015 02:16 CST

Hello.  Thanks for this post.  I've been using the original script at blogs.citrix.com/.../.  It works fine when I run it from a powershell console.  

There is a problem when running it from a scheduled task though.  Most of the script runs great.  The problem is when it tries to launch the app from the resource page.  It's like it never gets "clicked".  The username I'm using is an admin on the system I'm running the script from.  I've tried many different formats of the powershell command in the scheduled task.  I tried converting the powershell to an exe with PowerGUI and executing that.  I tried using psexec to launch it from the scheduled task.  I also changed the script to assigned info in the script instead of putting them in a command.

Do you have any ideas I could try?  Here is the log.

[03/27/2015 07:43:50.986]: Setting Internet Explorer visible
[03/27/2015 07:43:51.001]: Navigating to 'https://NetscalerURL'
[03/27/2015 07:43:51.126]: Internet Explorer: BUSY
[03/27/2015 07:44:11.157]: Internet Explorer: BUSY
[03/27/2015 07:44:31.189]: Accessing DOM
[03/27/2015 07:44:31.329]: Detecting NetScaler Gateway or StoreFront login form...
[03/27/2015 07:44:31.845]: Try #1: SUCCESS
[03/27/2015 07:44:31.845]: NETSCALER GATEWAY DETECTED
[03/27/2015 07:44:31.861]: Getting Login button
[03/27/2015 07:44:31.861]: Getting UserName textbox
[03/27/2015 07:44:32.157]: Getting Password textbox
[03/27/2015 07:44:32.157]: Setting UserName 'username'
[03/27/2015 07:44:32.189]: Setting Password
[03/27/2015 07:44:32.189]: Clicking login button
[03/27/2015 07:45:12.251]: Getting SF resources page...
[03/27/2015 07:45:12.470]: Try #1: SUCCESS
[03/27/2015 07:45:12.486]: Getting resource 'App Name'...
[03/27/2015 07:45:12.736]: Try #1: SUCCESS
[03/27/2015 07:45:12.767]: Found 0 session(s) before clicking 'App Name'
[03/27/2015 07:45:12.767]: Clicking resource 'App Name'
[03/27/2015 07:45:12.767]: Sleeping 60 seconds...
[03/27/2015 07:46:12.798]: Verifying that session launched...
[03/27/2015 07:46:12.814]: Try #1: FAIL
[03/27/2015 07:46:17.830]: Try #2: FAIL
[03/27/2015 07:46:22.830]: WARNING: Unable to confirm that session launched
[03/27/2015 07:46:22.845]: Sleeping 15 seconds before logging off...
[03/27/2015 07:46:37.861]: Getting log off link...
[03/27/2015 07:46:37.861]: Try #1: SUCCESS
[03/27/2015 07:46:37.876]: Clicking log off link
[03/27/2015 07:46:37.908]: Quitting Internet Explorer
[03/27/2015 07:46:41.939]: Releasing Internet Explorer COM object
[03/27/2015 07:46:42.236]: ***************  LAUNCHER SCRIPT END  ***************

Thanks a lot for any info\insight you can provide!


Stan Czerno
March 27, 2015 03:11 CST

When you are Scheduling the Task, are you setting "Run with highest privileges"?

I have seen that sometimes the first attempt on a computer always fails, something with the ICO does not work. After that they work correctly.

Here are some screenshot of how my Task is setup:


Program/Script: %SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe

Add Argument: -executionpolicy bypass -file c:\bin\SFLauncher2.ps1 -SiteURL "https://citrix.czerno.com"; -UserName "<UserName>" -Password "<Password>" -smtpServer "<mailServer>" -emailFrom "<EmailAddress>" -emailTo "<EmailAddress>" -LogFilePath C:\Bin -LogFileName SFLauncher.log "App1" "App2"

Start in: C:\bin

Jamey Lanzalaco
March 27, 2015 09:14 CST

Yup.  I'm using "highest privileges".  Thanks for the scheduled task notes.  I'll give it a shot and post back.


April 8, 2015 05:50 CST

Hi Stan.  It has been a little while but I wanted to post back and let you know that I am able to run the script as a scheduled task in a windows 7 vm with ie 8 when I have the proper security configuration.  But I still can't run the script through a scheduled task in a windows 2012 r2 system using ie 11.  Have you had any issues with ie11?

I'm going to keep working on it and testing so I'll let you know how it goes.


Stan Czerno
April 8, 2015 07:04 CST

I have not had any issues with IE11, but I have never tested it from Windows Server 2012 R2. I have only ran it from Windows 7, 8 and 10.

Chris Straight
September 4, 2015 06:50 CST

I found it pretty easy to update for StoreFront 3.0. I only tested it through a gateway as I didn't have a direct connection to StoreFront 3.0, but it looks like the loginUI uses the same elements.

The only things I had change was to add a new element to check for when SF 3.0 was loaded and changed the logoff element. The 1st one checks for "favorites" to be loaded and the second one uses the new log off button ID.

Set-Variable -Name SFMyFavorites -Value "myAppsBtn" -Option Constant -Scope Script
Set-Variable -Name SFLogOffLinkId -Value "menuLogOffBtn" -Option Constant -Scope Script

Great script!

Stan Czerno
September 4, 2015 07:16 CST

Good deal! I will have to mess around with and publish a new version. Thanks for the assistance!

Stan Czerno
September 8, 2015 06:29 CST

A new version of the script has been posted here: www.czerno.com/.../powershell-script-to-launch-one-or-more-published-applications-from-storefront-2-x-and-3

March 24, 2016 02:05 CST

Stan where you able to make this work with WI 5.4?
running 6.5 with wi 5.4

Stan Czerno
March 24, 2016 03:17 CST

I have not attempted it. You know Storefront works with XenApp 6.5, right? Storefront 3.x is a great improvement over 2.x.

April 28, 2016 03:04 CST


This script was really amazing. But, every time its throwing me an error stating that the username or password are invalid. I can able to make a login with the same manually.

Could you please assist me where I am doing wrong in the script or do I need to modify anything in the script.

Thanks In Advance.


Comments are closed