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 Else IsOutlookRunning = False End If NextEnd Function
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.
Comments (1)
Commented: