Community Pick: Many members of our community have endorsed this article.
Editor's Choice: This article has been selected by our editors as an exceptional contribution.

Change IsOutlookSignature in a Citrix / Terminal Server environment

This is an addendum to the following article:

Acitve Directory based Outlook Signature

The script is fine, and works in normal client-server domains.

If you want to use the script on a Citrix or Terminal Services server, the IsOutlookFunction stops if anyone on the server has Outlook running.  In this case, you want to check only if Outlook is running for the current user:

I changed the code as follows:

Function IsOutlookRunning()
                      	strComputer = "."
                      	strQuery = "Select * from Win32_Process " & _
                      	"Where Name = 'OUTLOOK.EXE'"
                      	Set objWMIService = GetObject("winmgmts:" _
                      	& "{impersonationLevel=impersonate}!\\" _
                      	& strComputer & "\root\cimv2")
                      	Set colProcesses = objWMIService.ExecQuery(strQuery)
                      	For Each objProcess In colProcesses
                      =>	    colProperties = objProcess.GetOwner(strNameOfUser,strUserDomain)
                      		If UCase(objProcess.Name) = "OUTLOOK.EXE" Then
                      =>		    If objSysInfo.Username = strNameOfUser Then		                             IsOutlookRunning = True
                      =>		   Else
                      =>		        IsOutlookRunning = False
                      =>		    End if
                      			IsOutlookRunning = False
                      		End If
                      End Function

Open in new window

This script checks for a running "Outlook.exe" process for the current user.

I found the code that I added from the Question/Answer "Hey, Scripting Guy! Blog" website.

Most of the time Google is your friend in finding the right code--you only have to know how to incorporate it into you're own scripts.

I used the GetOwner method, which returns two variables--one that returns the name of the user who 'owns'  the process, and another that returns the domain that the user belongs to.  We do not need the domain, so I left it alone.  In my script above, I used variables named "strUserName" and "strUserDomain".  These names are not important--you can call the variables "A" and "B", or "X" and "Y", or anything you want--however, a descriptive name is preferable.

Each "Outlook.exe" process is examined to see if the owner is the current user.  When the owner is the current user, we will use IsOutlookRunning to check if Outlook is running.  If it is running, IsOutlookRunning returns TRUE.  In all other cases, where Outlook is not running, or all Outlook processes are owned by other users, IsOutlookRunning returns FALSE.

I hope this code is useful for people who want to use an automated signature with Outlook on Terminal Services or Citrix servers.

Of course, this method may be used in many other cases where you want to know the owner of a process.

Kind regards,

Carlo van Orsouw
Princen Group
The Netherlands

Comments (1)

Mark WillsTopic Advisor
Distinguished Expert 2018

Good Tip ! Thanks, will keep this one handy...

Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.