Detect Outlook installed and load dynamically INterop.Outlook

人走茶凉 提交于 2019-12-02 02:23:54
pharring

To detect if Outlook is installed, look for the "Outlook.Application" ProgID.

From an installer, look in the registry for HKEY_CLASSES_ROOT\Outlook.Application

At runtime, you can do this:

using System;
using Microsoft.Office.Interop.Outlook;

class Program
{
    static void Main(string[] args)
    {
        var outlookType = Type.GetTypeFromProgID("Outlook.Application");
        if (outlookType == null)
        {
            Console.WriteLine("Not installed.");
        }
        else
        {
            var app = Activator.CreateInstance(outlookType) as Application;
            Console.WriteLine(app.Name);
        }
    }
}

To avoid the problem of dynamically loading the interop, you should set Embed Interop Types to true for Microsoft.Office.Interop.Outlook.Interop.dll

check the Installer APIs to detect the install state of Outlook or use one of the method described here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!