C# 使用提升的权限运行时如何与Outlook互操作?
在调试Outlook Interop的问题时,我注意到,当以管理员组的一部分用户身份启动进程时,我的应用程序按预期工作。但是,在提升权限下以同一用户的身份运行它会失败 只要我们尝试进行互操作,问题一出现就可以很容易地重现 尝试创建新实例时:C# 使用提升的权限运行时如何与Outlook互操作?,c#,.net,outlook,office-interop,com-interop,C#,.net,Outlook,Office Interop,Com Interop,在调试Outlook Interop的问题时,我注意到,当以管理员组的一部分用户身份启动进程时,我的应用程序按预期工作。但是,在提升权限下以同一用户的身份运行它会失败 只要我们尝试进行互操作,问题一出现就可以很容易地重现 尝试创建新实例时: var NewOutlookApp = new Application(); // Crashes if Outlook is already running: System.Runtime.InteropServices.COMException: La
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.
尝试检索现有实例时:
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