Friday, August 23, 2013

Lync PresenceIndicators while in UI Suppressed Mode in Outlook

The title is not possible.  You cannot run Lync in UISuppressedMode and still get the presence indicators in Outlook.  The versions I tried this with were Lync 2010 and Outlook 2010.  The reason is when you enable UISuppressedMode Microsoft disables the Lync.Model.Control which Outlook uses to enable the PresenceIndicators.

Since we use Outlook and Lync in Citrix and part of the requirement of us publishing Outlook was to have these presence indicators available (along with the call and other functions) UISuppressedMode was not an option.  In addition, we required the application to try and act as a single app, so when Outlook was closed, Lync would NOT hold the session.  The users requested Lync be hidden because two applications launching at the same time is confusing; so I wrote a script to try and simulate this functionality as much as possible.  This was the result:


;
; AutoIt Version: 3.0
; Language:       English
; Platform:       Win9x/NT
; Author:         Trentent Tye (trententtye@hotmail.com)
;
; Script Function:
;   Opens Lync in a hidden window, starts Outlook then polls the user session
;  to see if the outlook.exe process is still running.  If it is not it will
;  log off the session.
;
;

ShellExecute ( "C:\Program Files (x86)\Microsoft Lync\communicator.exe", "", "" , "" , @SW_HIDE )
WinWaitActive("Microsoft Lync","",5)
WinSetState ( "Microsoft Lync", "", @SW_HIDE )
Run ( "C:\Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE")
Sleep(5000)


#include

AutoItSetOption ( "TrayIconHide" , 1 )
$arrProcesses = _GetProcessIds(@ComputerName)
_ArrayDisplay($arrProcesses)

Func _GetProcessIds($strHost)
    Local $var = EnvGet("SESSIONNAME") ;get session name of current session (eg RDP-TCP#0)
 
   ;match current session name to sessionID
   ;We do this by matching the current session's environment variable "SESSIONNAME" to the
   ;numeral registry value under HKCU\Volatile Environment which actually equals the session ID
   ;We do this because on Citrix you could be running multiple apps from the same server
   ;and we only want to disconnect the session that terminated the monitored application.
   For $i = 1 To 10
    Local $vol = RegEnumKey("HKEY_CURRENT_USER\Volatile Environment", $i)
    If @error <> 0 Then ExitLoop
   Local $key = RegRead("HKEY_CURRENT_USER\Volatile Environment\"& $vol, "SESSIONNAME")
     If $key == $var Then
        ;MsgBox(4096, "Found SessionID and Name", $vol & " " & $key )
        Local $session = $vol
     EndIf
    Next
 
   ;Now that we have the session ID we can query the list of all processes on this terminal
   ;and match the session ID returned per process and compare it to our current session ID
   ;MsgBox(4096, "Session is:", $session)
    While -1 ;infiniteloop
   $outlookFound = "0"
    If Not Ping($strHost,200) Then SetError(1)
    $objWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strHost & "\root\CIMV2")
    If Not IsObj($objWMI) Then SetError(2)
    $colItems = $objWMI.ExecQuery ("SELECT * FROM Win32_Process")
    Dim $arrResults[1][3] = [["Processname","ProcessID","SessionID"]]
   ;we now have a array of all processes on the system
 

    ;every 25 seconds we check to see if our process is running
    Sleep(25000) ;twenty-five seconds

    For $objItem In $colItems
        ReDim $arrResults[UBound($arrResults)+1][3]
       If $objItem.SessionId == $session Then ;we only want those processes that match our current session ID
          ;MsgBox(4096, "Session ID:", $objItem.SessionId)
          $arrResults[UBound($arrResults)-1][0] = $objItem.Name
          ;$arrResults[UBound($arrResults)-1][1] = $objItem.ProcessId
          ;$arrResults[UBound($arrResults)-1][2] = $objItem.SessionId
          ;MsgBox(4096, "Process Name", $objItem.Name)
          If $objItem.Name = "outlOok.exe" Then ;Is our process running?  If true set variable to 1
             $outlookFound = "1"
             ;MsgBox(4096, "Outlook Found", "Keep chugging along")
          EndIf
       EndIf
    Next
    if $outlookFound = "0" Then ;if process was found then this statement will be skipped
     ;MsgBox(4096, "Outlook Not Found", "Logging off")
     Run("shutdown.exe -l -f") ;Force a logoff
     ;Exit
     EndIf
    WEnd
 EndFunc


No comments: