Detect Outlook installed and load dynamically INterop.Outlook

自闭症网瘾萝莉.ら 提交于 2019-12-02 03:20:30

问题


I have a Windows Forms application in VS2010. It has a reference to Interop.Outlook (2003). Then, I have reinstalled Windows XP and VS2010, but not install Outlook.

Now, the project not compiles.

I think this, my application will not work if Outlook not installed in machine that my program executes on.

I need to know if I detect Outlook installed, and load dynamically Interop.Outlook.dll (for using the Outlook PIA or Embedded Interop types in .NET 4).

If the machine has Outlook (2003, 2007, 2010, perhaps need code to detect version and do compatibility of Outlook versions) installed, the application works fine with functionally Outlook.

If the machine hasn't Outlook installed, the application works fine without functionally Outlook.

Any sample source code or goog patterns and practices about it??


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/4421176/detect-outlook-installed-and-load-dynamically-interop-outlook

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