VirtualizationAdmin.com

One of the most common questions to the Citrix List is how do I keep people from running a program more than once.

Here is one solution.

Server Boss

It prevents users from logging on more than once to a Winframe/Metaframe session. You can download a demo here.

This is a script from the list archives on how to do this....

I use a script to prevent a program, in my case word or excel, to start more than once. Hope this helps.

@echo off
query process | find /i "excel.exe" >nul
if not errorlevel 1 goto LOGOFF
goto CONT

:LOGOFF
rem The following line sends a message to the user.
msg %WINSTATIONNAME%
Microsoft Excel is already active.
goto END

:CONT
@echo off
CLS
ECHO .
ECHO Please wait while Microsoft Excel is started ...
ECHO .
START M:\Micros~1\Office\Excel.exe

:END

Here is a recent posting to the citrix list on a batch script to keep users from logging on more than once.

Credit goes to: "Watkins, Jason PMCNA"

Here's a simple batch file that we use as a login script that does what you're wanting:

@echo off
echo Welcome to Company Name. | msg /TIME:1 /W %USERNAME%
qwinsta %USERNAME% | find /C "%USERNAME%" > %TEMP%\%USERNAME%.CNT
REM Then compare with a file (ONE.CNT) produced by the same command when only
REM one session is in use.
REM (its content will be 1 and a blank line)
echo N|comp /A %TEMP%\%USERNAME%.CNT \\PMC01naSRV02\NETLOGON\ONE.CNT
REM Test differences
if not errorlevel 1 goto LOGIN
REM Send popup message to every display used by %USERNAME% and wait 10 seconds
Echo Already connected elsewhere. Logout in 10 seconds... | msg /TIME:10 /W
%USERNAME%
REM Remove temporary file
del %TEMP%\%USERNAME%.CNT
REM logoff %USERNAME%
logoff

:LOGIN
REM Remove temporary file
del %TEMP%\%USERNAME%.CNT

Here is another solution to run an app only once from the Citrix KB

Limiting Concurrent Logins

Synopsis:

For administrators who want to control how many logins a user receives, the following low tech workaround is available.

Details:

Currently, there is no setting in User Manager for Domains to limit user's concurrent logins. In this series of "low-tech workarounds", we explore ways to use the Citrix application publishing system to acquire control of concurrent logins.

In preparation, the only requirement is a user-specific directory where the user is allowed to create and erase files. The first choice is usually the user's home directory.

The steps are:

  1. Publish an application that runs a batch file.
  2. Create the batch file that looks just like this:

    @echo off
    rem *
    rem * Low tech workaround for login concurrency control.
    rem *
    rem * This example is for the MetaFrame desktop
    rem *
    
    rem Wait on redirector to connect home directory. Everyone has a win.ini file, so check if it exists.
    echo Connecting...
    :delay
    IF EXIST %homedrive%%homepath%\windows\win.ini GOTO start
    goto :delay
    
    rem Now, check for a little something that only exists if the user has already logged in.
    rem If not, create it. In this case, a little text file called trigger.txt
    :start
    cls
    IF EXIST %homedrive%%homepath%\trigger.txt GOTO :goodbye
    DIR %homedrive%%homepath% /w > %homedrive%%homepath%\trigger.txt
    
    rem At this point, the user has not logged in before, so execute the application
    START /NORMAL /WAIT Explorer.exe
    
    rem Delete the trigger after closing the application
    del %homedrive%%homepath%\trigger.txt
    
    :goodbye
    		

The following information helps in modifying the branching logic in the above batch file:

The IF statement performs conditional processing in batch programs.

IF [NOT] ERRORLEVEL number command
IF [NOT] string1==string2 command
IF [NOT] EXIST filename command

NOT: Specifies that Windows NT should carry out the command only if the condition is false.

ERRORLEVEL: number Specifies a true condition if the last program run returned an exit code equal to or greater than the number specified.

command: Specifies the command to carry out if the condition is met.

string1==string2: Specifies a true condition if the specified text strings match.

EXIST filename: Specifies a true condition if the specified filename exists.

If Command Extensions are enabled IF changes as follows:

IF [/I] string1 compare-op string2 command
IF CMDEXTVERSION number command
IF DEFINED variable command

where compare-op may be one of:

  • EQU - equal
  • NEQ - not equal
  • LSS - less than
  • LEQ - less than or equal
  • GTR - greater than
  • GEQ - greater than or equal

and the /I switch, if specified, says to do case insensitive string compares. The /I switch can also be used on the string1==string2 form of IF. These comparisons are generic in that if both string1 and string2 are both comprised of all numeric digits, the strings are converted to numbers and a numeric comparison is performed.

The CMDEXTVERSION conditional works just like ERRORLEVEL, except it is comparing against an internal version number associated with the command Extensions. The first version is that it is incremented by one when significant enhancements are added to the Command Extensions. CMDEXTVERSION conditional is never true when Command Extensions are disabled.

The DEFINED conditional works just like EXISTS except it takes an environment variable name and returns true if the environment variable is defined.

%ERRORLEVEL% expands into a string representation of the current value of ERRORLEVEL, provided that there is not already an environment variable with the name ERRORLEVEL, in which case you will get its value instead. Using this and the above numerical comparision operators, you can do the following

choice
goto answer%ERRORLEVEL%
:answer0
echo You typed Y for yes
:answer1
echo You typed N for no

you can also using the numerical comparisons above:

IF %ERRORLEVEL% LEQ 1 goto okay

%CMDCMDLINE% expands into the original command line passed to CMD.EXE prior to any processing by CMD.EXE, provided that there is not already an environment variable with the name CMDCMDLINE, in which case you will get its value instead.


Receive all the latest articles by email!

Receive Real-Time & Monthly MSTerminalServices.org article updates in your mailbox. Enter your email below!
Click for Real-Time sample & Monthly sample

Become an MSTerminalServices.org member!

Discuss your Terminal Services & Citrix issues with thousands of other SBC experts. Click here to join!

Solution Center