[古怪問題] 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, 用管理員方式運行該代碼。 也是沒法正常獲取到對象。
相關文章
相關標籤/搜索