[古怪问题] 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.
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
· 本地部署DeepSeek后,没有好看的交互界面怎么行!
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 趁着过年的时候手搓了一个低代码框架
· 推荐一个DeepSeek 大模型的免费 API 项目!兼容OpenAI接口!
· 用 C# 插值字符串处理器写一个 sscanf
2017-03-07 .NET 同步与异步 之 警惕闭包(十)