John P
John P

Reputation: 349

Get Existing Outlook Addin Information from External C# Application

I already have a C#-based Outlook Addin application which may or may not be installed on my clients versions of Outlook. Is it possible to determin whether the addin is installed and enabled from an external C# application, running on the same client's machine? And if so, how?

Many thanks in advance! John

Upvotes: 0

Views: 173

Answers (2)

John P
John P

Reputation: 349

In the end, the following code solved my problem:

using System.Reflection;
using System.Runtime.InteropServices;
using Outlook = Microsoft.Office.Interop.Outlook;
using Microsoft.Office.Core;

...

public static bool IsOutlookAddinEnabled(string addinName)
{
    bool isEnabled = false;

    Outlook.Application outlookApp = null;

    if (System.Diagnostics.Process.GetProcessesByName("OUTLOOK").Length > 0)
    {
        outlookApp = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;
    }
    else
    {
        outlookApp = new Outlook.Application();
        Outlook.NameSpace nameSpace = outlookApp.GetNamespace("MAPI");
        nameSpace.Logon("", "", Missing.Value, Missing.Value);
        nameSpace = null;
    }

    try
    {
        COMAddIn addin = outlookApp.COMAddIns.Item(addinName);
        isEnabled = addin.Connect;
    }
    catch { }

    return isEnabled;
}

Many thanks to Mitch for his quick response.

Upvotes: 0

Mitch
Mitch

Reputation: 22301

If you are installing via MSI, you can check if it has been installed with the Windows Installer API (see MSDN for more, P/Invoke.net has a C# example).

Upvotes: 1

Related Questions