XenApp 7.5 how to limit only one application instance for user

Home/XenApp/XenApp 7.5 how to limit only one application instance for user

XenApp 7.5 how to limit only one application instance for user

Share this post

One of the changes we do not like in new XenApp 7.5 is missing option to limit the number of application instances allowed to run on the server or limit only one instance of application for each user. In XenApp 6.5 I used this option very often and I was requested by one of my clients to find a workaround for that.

The simplest and in my opinion only available method is to use external script or batch file to run published application. The logical structure of this script should be the following:

Script start

Step 1 – check if special file or registry key exist in agreed location in user profile.

Step 2a – if  file/reg key exist display custom message to inform user that only one instance is allowed.

Step 2b – if  file/reg key not exist, copy/create a file/reg key to the agreed location and  run application executable

Step 3  – when application is closed delete file/reg key from user profile.

Script end

 

I prepared an initial version of VBS script and you can download it from here. Please note I’m not a scripting master and I’m open for any comments and modifications if you feel that this script can be optimized.

 

‘///
‘/// Created by: Andrzej Golebiowski
‘/// Created on: 2014-07-22
‘/// Purpose: Limit number of application instances to 1
‘///

Const HKEY_CURRENT_USER = &H80000001

‘/// Declare variable for application
AppName = “Notepad”

‘/// Check if appliacation the Run key exist
strComputer = “.”
Set objRegistry = GetObject(“winmgmts:\\” & strComputer & “\root\default:StdRegProv”)

strKeyPath = “Software\Citrix24\” & AppName & “\”
strValueName = “Run”
dwValue = 1

objRegistry.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue

‘/// Execute application or display message to the user
If IsNull(strValue) Then
‘/// Create applicaton Run key
objRegistry.CreateKey HKEY_CURRENT_USER, strKeyPath
objRegistry.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, dwValue

‘/// Run application
sub shell(cmd)
dim objShell
Set objShell = WScript.CreateObject( “WScript.Shell” )
objShell.Run(cmd),1,True
Set objShell = Nothing
end sub
shell “notepad”

‘/// Delete applicaton Run key
objRegistry.DeleteKey HKEY_CURRENT_USER, strKeyPath

Else
‘/// Display message
Wscript.Echo “You already have an instance of this application open and are not allowed to run more than one instance. Please close open application instance or contact your System Administrator.”

End If

‘/// Script end

 

 

By | 2016-12-18T19:21:33+00:00 July 23rd, 2014|XenApp|12 Comments

About the Author:

I’m a Citrix Architect with 17 years experience in Microsoft and Citrix infrastructure. I have been working with Citrix since Metaframe 1.8 and my primary focus is on Server, Desktop and Application virtualisation with a preference for Citrix products. I’m an enthusiast of Citrix XenDesktop and Provisioning Server.

12 Comments

  1. David Figueroa July 26, 2014 at 7:11 pm - Reply

    I think you are absolutely correct about needing a script to accomplish the goal. However, this script only works within a single server – if the users are hitting multiple servers, then your script won’t track them. . You really need a central location to track the usage of an application. Ultimately, you’ll want either a central home directory, a central file share, or Active Directory to track the usage.

    But, the methodology is solid. The only place you will run into trouble with it is if user session crashes ungracefully, in which case, you’ll have to clean it by hand, or make the script a lot more complicated.

    David F.

    • Andrzej Gołębiowski July 27, 2014 at 11:02 pm - Reply

      David,
      Thank you for your comments. I fully agree that the script needs more effort to make it working in complex, multiserver environment. I just published the first, beta version of the script. All sugestions are more than welcome and will help me to prepare the better script.

      I hope in the next version of XenApp this option will be back. This is the best solution and all our scripting is only the workaround.

      Andrzej

  2. Andre Navoizat September 30, 2014 at 2:45 pm - Reply

    Good script but if a user connect on another server he can start two instance.
    Looks like there is no session affinity.
    Andre

    • Andrzej Gołębiowski September 30, 2014 at 3:09 pm - Reply

      Yes, I know. I’m working on the new version of the script. I will publish it soon.

  3. Saša Petrović October 30, 2014 at 10:29 am - Reply

    This script hasn’t work for me, until I’ve changed objRegistry.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, dwValue to objRegistry.SetSTRINGValue….

    • Andrzej Gołębiowski October 30, 2014 at 11:50 am - Reply

      Hi,
      Yes, I know that this script is not perfect. I’m working on a new solution to solve the problem when application is published on multiple servers.

      Regards
      Andrzej

  4. Adam November 16, 2014 at 3:29 am - Reply

    Why not use the xendesktop powershell SDK for this.

    While not something like

    $app = Get-BrokerApplication Notepad
    Get-BrokerSession -UserName MyDomain\MyAccount -ApplicationUid $app.Uid

    privileges may be an issue though

    • Andrzej Gołębiowski November 17, 2014 at 10:02 am - Reply

      Yes, this is a method I used in the solution I’m currently working on.

      I will finish this soon

      • Shekhar Reddy September 8, 2015 at 6:03 am - Reply

        Hi,

        Have you made it ? If yes, could you please share the script we are currently looking to limit sessions to single for a particular application.

  5. Andrey January 22, 2015 at 2:25 am - Reply

    Hello, Andrzej,
    Thanks for your ultimately helpful blog.
    I faced with same issue of application limiting on xenapp7.6 for multi server farm. Is it possible for you to share some more ideas on your new solution?

    Thanks,
    Andrey.

  6. Steve June 11, 2015 at 10:19 pm - Reply

    Hi Andrzej,

    Any update on this? Were you able to get something working for multi server farm?

    Thanks,
    -Steve

  7. Shiron July 28, 2015 at 5:32 pm - Reply

    Hi Andrzej,

    This script can be useful for me .
    i’m not familier with scripts but can you please explain what should i need to do with this ?
    should I compile it ? or there is a faster way to do it?

    Thanks in advance.
    -Shiron

Leave A Comment

To protect our website from spam. * Time limit is exhausted. Please reload the CAPTCHA.