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

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

问题描述

我在 VS2010 中有一个 Windows 窗体应用程序.它参考了 Interop.Outlook (2003).然后,我重新安装了 Windows XP 和 VS2010,但没有安装 Outlook.

现在,项目无法编译.

我认为,如果 Outlook 没有安装在我的程序执行的机器上,我的应用程序将无法运行.

我需要知道我是否检测到 Outlook 已安装,并动态加载 Interop.Outlook.dll(用于在 .NET 4 中使用 Outlook PIA 或嵌入式互操作类型).

如果机器安装了 Outlook(2003、2007、2010,可能需要代码来检测版本并做 Outlook 版本的兼容性),该应用程序可以正常使用 Outlook.

如果机器没有安装 Outlook,则应用程序在没有 Outlook 功能的情况下也能正常工作.

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

解决方案

要检测是否安装了 Outlook,请查找Outlook.Application"ProgID.

从安装程序中,在注册表中查找 HKEY_CLASSES_ROOTOutlook.Application

在运行时,您可以这样做:

使用系统;使用 Microsoft.Office.Interop.Outlook;课程计划{静态无效主(字符串 [] args){var OutlookType = Type.GetTypeFromProgID("Outlook.Application");如果(outlookType == null){Console.WriteLine("未安装.");}别的{var app = Activator.CreateInstance(outlookType) 作为应用程序;Console.WriteLine(app.Name);}}}

为避免动态加载互操作的问题,您应将Microsoft.Office.Interop.Outlook.Interop.dllEmbed Interop Types设置为true>

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??

解决方案

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

From an installer, look in the registry for HKEY_CLASSES_ROOTOutlook.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

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

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