问题
I have written a VBScript for Outlook that forwards email which are lying unread in the inbox for more than 30 minutes. When I manually run the vbs file it works perfectly fine, but when I trigger is through Windows Task Scheduler it gets stuck. Seems like it does not hit the Outlook and stops executing at the CreateObject(...)
statement.
Could you please let me know how should I go about. I want to schedule it to run the script over Outlook every 30 min.
回答1:
When I manually run the vbs file it works perfectly fine, but when I trigger is through Windows Task Scheduler it gets stuck.
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.
As a workaround you may consider using EWS if you deal with Exchange profiles only, see EWS Managed API, EWS, and web services in Exchange. Or Outlook REST API which is available for Office 365 users, see Get Started with Mail, Calendar, and Contacts REST APIs.
Also you may consider using a low-level API on which Outlook is based on - Extended MAPI. Or just any other third-party wrapper around that API such as Redemption.
来源:https://stackoverflow.com/questions/43435188/runing-vbscript-code-for-outlook-through-a-scheduler