【问题标题】:How to Interop with Outlook when running with elevated privileges?以提升的权限运行时如何与 Outlook 互操作?
【发布时间】:2018-11-29 19:33:46
【问题描述】:

在调试 Outlook Interop 的问题时,我注意到当以属于管理员组的用户身份启动我的进程时,我的应用程序按预期工作。但是,在提升的权限下以同一用户身份运行它会失败。

一旦我们尝试进行互操作,问题就可以很容易地重现。

尝试创建新实例时:

var NewOutlookApp = new Application();
// Crashes if Outlook is already running: System.Runtime.InteropServices.COMException: La récupération de la fabrique de classes COM pour le composant avec le CLSID {0006F03A-0000-0000-C000-000000000046} a échoué en raison de l'erreur suivante : 80080005 Échec de l'exécution du serveur (Exception de HRESULT : 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
// This translates to: retrieving the COM class factory for componant with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error : 80080005 Failed to run server (HRESULT Exception : 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
// If Outlook isn't already running this works as expected.

尝试检索现有实例时:

var ExistingOutlookApp = (Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Outlook.Application");
// Crashes if Outlook is not running (Expected behaviour).
// Crashes even if Outlook is already running: System.Runtime.InteropServices.COMException (0x800401E3): Opération non disponible (Exception de HRESULT : 0x800401E3 (MK_E_UNAVAILABLE))
// This translates to: Operation not available.

这是预期的行为吗? 如果是这样,当两个进程以同一用户身份运行时,在以提升权限运行的应用程序和在没有提升权限的情况下运行 Outlook 之间进行互操作的适当方法是什么?

环境配置:

  • Windows 10,完全最新

  • Outlook 2016 点击运行

  • 互操作库:14.0.0.0

  • Visual Studio 2017

【问题讨论】:

    标签: c# .net outlook office-interop com-interop


    【解决方案1】:

    您必须在相同的安全上下文下运行这两个应用程序。没有任何可能的解决方法来解决该问题。您可以做的最好的事情是让用户知道或要求他们在相同的安全上下文(特权)下运行这两个应用程序。例如,您可以查看 Windows 中正在运行的进程列表,因此如果您在那里看到 Outlook.exe 并且无法获取正在运行的 Outlook 实例,则通知它们是有意义的。

    【讨论】:

    • 我理解您提出的问题,但是在我的情况下,要求非技术最终用户采取技术行动显然不是一种选择。有没有办法解决这个问题?否则我认为我将不得不求助于产生一个额外的(非特权)进程来处理互操作。
    • 没有别的办法。
    猜你喜欢
    • 1970-01-01
    • 2017-09-08
    • 1970-01-01
    • 2013-11-09
    • 1970-01-01
    • 2011-08-31
    • 2020-05-21
    • 2011-12-16
    相关资源
    最近更新 更多