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

问题:

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

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

 

 

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

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%A7

 

 

搜索资料:

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

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

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, 用管理员方式运行该代码。 也是无法正常获取到对象。
 
 
 

转载于:https://www.cnblogs.com/08shiyan/p/10487943.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值