COMException (0x800401E3): Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE)) with scheduled task

不想你离开。 提交于 2020-01-02 08:22:13

问题


After searching on the web without success, here's my question.

I've a task that i want to schedule to retrieve the attachment of an email from outlook and extract the data. It works fine when I launch the task manually but whenever I try to launch it through a scheduled task it fails with the error :

COMException (0x800401E3): Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))

It occurs when the program tries to retrieve or create an instance of Outlook as follow:

private Application GetApplicationObject()
    {

        Application application = null;

        if (Process.GetProcessesByName("OUTLOOK").Any())
        {
            application = Marshal.GetActiveObject("Outlook.Application") as Application;
        }
        else
        {
            application = new Application();
        }
        return application;
    }

I tried several ways (batch file, .exe file, parameter from a program) but they all failed. It was launched with the same account that was use to launch the task manually.

Can someone help me ? Any help would be appreciated! Cheers!


回答1:


Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. Read more about that in the Considerations for server-side Automation of Office article.

You may consider using a low-level API (or any other third-party wrappers) - Extended MAPI on which Outlook is based on. Or EWS in case of Exchange profiles, see EWS Managed API, EWS, and web services in Exchange for more information.




回答2:


Just a couple of thoughts:

  1. It could be a GUI issue. According to this answer, GUI tasks cannot be run from scheduled tasks. There may be a workaround, but I am not aware of one.

  2. It could be a context or permission issue. What settings are you configuring in the task, and are they the same as when you run the task outside of task scheduler?



来源:https://stackoverflow.com/questions/33544102/comexception-0x800401e3-operation-unavailable-exception-from-hresult-0x8004

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!