通过Windows服务运行时,操作不可用(来自HRESULT的异常:0x800401E3(MK_E_UNAVAILABLE))? [英] Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE)) when running through Windows Service?
问题描述
我试图从Windows Service挂接到Outlook应用程序,但遇到异常操作不可用(HRESULT异常:0x800401E3(MK_E_UNAVAILABLE))是我的代码.
i am try to hook to outlook application from windows Service but getting an exception Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE)) here is my code.
public void ItemSendEvent()
{
try
{
if (Process.GetProcessesByName(ApplicationConstants.OUTLOOK_PROCESS_NAME).Count() > 0)
{
// If so, use the GetActiveObject method to obtain the process and cast it to an Application object.
outlookApplication = Marshal.GetActiveObject(ApplicationConstants.OUTLOOK_APPLICATION_NAME) as Microsoft.Office.Interop.Outlook.Application;
Microsoft.Office.Interop.Outlook.NameSpace nameSpace = outlookApplication.GetNamespace(ApplicationConstants.OUTLOOK_NAME_SPACE);
nameSpace.Logon("", "", Missing.Value, Missing.Value);
nameSpace = null;
outlookApplication.ItemSend += outlookApplication_ItemSend;
}
log.Info("Outlook Item Send event registered successfully.");
}
catch (System.Exception ex)
{
log.Error("Exception occurred while registering Outlook Item Send event. " + ex.Message);
}
}
但是当我通过Windows窗体应用程序启动它时,它具有相同的代码.我浏览了一些网站,他们说Outlook对象不在ROT表中.解决办法是什么.
but the same code when i launch it through Windows Form Application its working Fine. i gone through some site's and they were saying that outlook object is not in ROT Table. what will be the solution.
推荐答案
Outlook或任何其他Office应用程序都无法在Windows服务中运行,即使您的服务以交互用户身份运行也是如此.仅扩展MAPI(仅C ++或Delphi)或扩展MAPI包装器,如兑换(其 RDO 系列对象.
Outlook, or any other Office app, cannot run in a Windows service even if your service is running as an interactive user. Only Extended MAPI (C++ or Delphi only) or an Extended MAPI wrapper like Redemption (its RDO family objects) can be used in a service.
在您的特定情况下,您似乎正在尝试捕获Application.ItemSend
事件.绝对没有理由为此创建Windows服务.创建一个COM加载项-只要Outlook本身在相同安全上下文中的同一进程中运行,它将由Outlook加载并运行.
In you particular case, it looks like you are trying to trap the Application.ItemSend
event. There is absolutely no reason to create a Windows service for that. Create a COM addin - it will be loaded by Outlook and run as long as Outlook itself is running in the same process in the same security context.
这篇关于通过Windows服务运行时,操作不可用(来自HRESULT的异常:0x800401E3(MK_E_UNAVAILABLE))?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!