[古怪问题] Marshal.GetActiveObject 在管理员模式下没法正常运行

问题:c#

var obj = Marshal.GetActiveObject("PowerPoint.Application") api

该代码在管理员模式下运行没法正常获取正在运行的 PPT PowerPoint.Application 对象,而在非管理员模式下能够正常获取。app

 

 

针对该问题,微软的msdn官方文档,也没有给予说明。post

https://docs.microsoft.com/zh-cn/dotnet/api/system.runtime.interopservices.marshal.getactiveobject?redirectedfrom=MSDN&view=netframework-4.7.2#%E5%AE%89%E5%85%A8%E6%80%A7this

 

 

搜索资料:spa

https://stackoverflow.com/questions/23698462/marshal-getactiveobjectoutlook-application-throws-mk-e-unavailable-when-debudebug

怀疑 :和用户有关,没有直接证据。code

This code run without problem in release r debug when Visual studio isn't started as an admin.对象

Marshal.GetActiveObject("Outlook.Application");

However, when I start Vs as administrator and run the same line in debug, I get the following error:文档

System.Runtime.InteropServices.COMException
Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))

How can I fix this.

I would guess that you are running Visual Studio as Administrator (started via Run as Administrator) while Outlook was opened as user, who was logged in as under Windows logon. So the Visual Studio is running under different user than Outlook client.
 
 
验证怀疑:用管理员方式运行PPT, 用管理员方式运行该代码。 也是没法正常获取到对象。
相关文章
相关标签/搜索