【发布时间】: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