为什么我的应用程序手动运行正常,但当我在任务计划程序中运行它时,它就会出错?

为什么我的应用程序手动运行正常,但当我在任务计划程序中运行它时,它就会出错?

我有一个应用程序,可以在任务计划程序中很好地运行在旧的 Windows 2008 R2 服务器上。它从一个 Web 服务读取数据,然后将一些数据写入另一个 Web 服务(因此需要网络访问)。过去几年,它在 Explorer 或任务计划程序中运行得同样好。我以域管理员的身份运行该进程(为了简单起见)。

我一直在努力将应用程序从旧服务器迁移到新 2012 R2 服务器,这需要对代码进行一些更改,这还不错。然而,我遇到了一个让我完全不知所措的问题。

应用程序现在可以正确运行,如果我在 Explorer 中双击了 EXE,它开始工作。但是,当我尝试使用与旧服务器相同的用户和设置在任务计划程序中运行该应用程序时,它会运行几秒钟然后停止(它应该运行 2 分钟)。

我已经设置了审计日志,但日志中没有显示任何内容。但是,我看到 Windows 应用程序日志在进程终止后显示了几个错误:

Application: WebInterfacer.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Runtime.InteropServices.COMException
  at SHDocVw.IWebBrowser2.get_Busy()
  at WebInterfacer.Transferer.waitForIE(SHDocVw.InternetExplorer)
  at WebInterfacer.Transferer.setTimes(Int32, System.String, System.String, System.Collections.Generic.List`1<ZoneEvent>, SHDocVw.InternetExplorer, System.String ByRef)
  at WebInterfacer.Transferer.GetAndSetData(System.Collections.Generic.Dictionary`2<System.String,Double>, WebInterfacer.BookingService.Lists, System.String, System.String, System.String, Int32, System.String ByRef)
  at WebInterfacer.Transferer.Main(System.String[])

第二个:

Faulting application name: WebInterfacer.exe, version: 1.0.0.0, time stamp: 0x588f5ae8
Faulting module name: KERNELBASE.dll, version: 6.3.9600.18340, time stamp: 0x5736541b
Exception code: 0xe0434352
Fault offset: 0x00014878
Faulting process id: 0x2ae4
Faulting application start time: 0x01d27b2075396488
Faulting application path: C:\Program Files\Internal\Transferer\WebInterfacer.exe
Faulting module path: C:\Windows\SYSTEM32\KERNELBASE.dll
Report Id: b8a9ddf0-e713-11e6-80be-42f2e9a1fc19
Faulting package full name: 
Faulting package-relative application ID: 

当我添加一些额外的错误检查代码时,我得到了“消息过滤器指示应用程序正忙。错误 HRESULT:0x8001010A (RPC_E_SERVERCALL_RETRYLATER)”。为什么它很忙?是否有一个策略阻止应用程序代码在 shell 中与 Windows 2012 R2 上的 IE 交互?

我已将进程设置为无论用户是否登录都运行。它设置为以最高权限运行。这在两个不同服务器上的两个版本中都是相同的。

我想知道 SHDocVw.InternetExplorer 和那里的 COM 对象是否有问题,但为什么在任务计划程序中运行时会失败,而手动运行时却不会失败?

提前致谢

答案1

这里有很多可能的原因导致它失败。

你必须调试它。你需要在代码中捕获异常并研究异常提供的数据。这样你就能找到错误的最终原因。

我根据经验猜测代码运行 IE,并等待其输出。从 Scheduler 启动的任务中的环境可能不同,因此 IE 或其他组件无法正常运行,因此它会引发异常。

相关内容