检测安装Outlook和动态加载INterop.Outlook [英] Detect Outlook installed and load dynamically INterop.Outlook

查看:146
本文介绍了检测安装Outlook和动态加载INterop.Outlook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows在VS2010窗体应用程序。它具有Interop.Outlook的引用(2003)。然后,我已经重新安装了Windows XP和VS2010,但不是安装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.

现在,该项目不编译。

我想这一点,如果没有安装在我的程序执行机器展望我的应用程序将无法正常工作。

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

我需要知道,如果我发现安装Outlook,和负载动态Interop.Outlook.dll(对于使用Outlook PIA或.NET 4中嵌入的互操作类型)。

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).

如果机器有展望(2003年,2007年,2010年,也许是需要代码来检测版本,并​​做安装Outlook版本的兼容性),应用程序工作正常功能Outlook中。

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.

如果在机器未安装Outlook,应用程序工作正常没有功能上的Outlook。

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

任何关于它的示例源代码或goog模式和做法??

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

推荐答案

要检测安装Outlook使用认准Outlook.Application进程id。
从一个安装程序,查看注册表HKEY_CLASSES_ROOT\Outlook.Application

To detect Outlook installed use the look for the "Outlook.Application" ProgID. From an installer, look in the registry for HKEY_CLASSES_ROOT\Outlook.Application

在运行时,做到这一点:

At runtime, 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);
        }
    }
}

要避免动态问题装载互操作,应设置嵌入互操作类型为true Microsoft.Office.Interop.Outlook.Interop.dll

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

这篇关于检测安装Outlook和动态加载INterop.Outlook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆