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
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.
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
Good script but if a user connect on another server he can start two instance.
Looks like there is no session affinity.
Andre
Yes, I know. I’m working on the new version of the script. I will publish it soon.
This script hasn’t work for me, until I’ve changed objRegistry.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, dwValue to objRegistry.SetSTRINGValue….
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
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
Yes, this is a method I used in the solution I’m currently working on.
I will finish this soon
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.
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.
Hi Andrzej,
Any update on this? Were you able to get something working for multi server farm?
Thanks,
-Steve
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