Monday, February 20, 2012

Check LyncClient.GetClient()

Check if Lync client is running on the users computer.

Required DLL's:
 Microsoft.Lync.Model.dll and for some reason Microsoft.Office.Uc.dll might be required for the GetClient not to throw a TypeInitializationException.



LyncClient.GetClient() calls the EnsureOI() method.



private static void EnsureOI()
{
if (s_officeIntegration == null)
{
try
{
if (!IsUISuppressed() && !IsRunning())
{
throw new ClientNotFoundException("The host process is not running", null);
}
s_officeIntegration = (UCOfficeIntegration)
Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("...")));
}
catch (COMException exception)
{
throw GetOCOMException(exception);
}
}
}





//Test if Lync is running and get object
try
{
   _lyncClient = LyncClient.GetClient();
   startClient();
}
catch (ClientNotFoundException ex)

{
   throw new Exception(ex.InnerException.ToString());

}
catch (TypeInitializationException ex)

{
   throw new Exception(ex.InnerException.ToString());

}
catch (NotStartedByUserException ex)

{
   throw new Exception(ex.InnerException.ToString());

}
catch (Exception ex)

{
   throw new Exception(ex.InnerException.ToString());

}

No comments:

Post a Comment