Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用提升的权限运行时如何与Outlook互操作?_C#_.net_Outlook_Office Interop_Com Interop - Fatal编程技术网

C# 使用提升的权限运行时如何与Outlook互操作?

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

在调试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.
尝试检索现有实例时:

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


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

我理解您提出的问题,但是在我的场景中,要求非技术最终用户采取技术行动显然不是一个选项。有没有办法解决这个问题?否则,我想我将不得不求助于生成一个额外的(非特权的)进程来处理互操作。