开发者

Detect Outlook installed and load dynamically INterop.Outlook

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 in开发者_如何学JAVAstalled, 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??


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜