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