简体   繁体   English

作为计划任务运行时,C#控制台程序无法发送传真

[英]C# console program can't send fax when run as a scheduled task

I have a console program written in C# that I am using to send faxes. 我有一个用C#编写的控制台程序,用于发送传真。 When I step through the program in Visual Studio it works fine. 当我在Visual Studio中逐步执行该程序时,它可以正常工作。 When I double click on the program in Windows Explorer it works fine. 当我双击Windows资源管理器中的程序时,它可以正常工作。 When I setup a Windows scheduled task to run the program it fails with this in the event log. 当我设置Windows计划的任务以运行程序时,此事件在事件日志中失败。

EventType clr20r3, P1 consolefaxtest.exe, P2 1.0.0.0, 
P3 48bb146b, P4 consolefaxtest, P5 1.0.0.0, P6 48bb146b, 
P7 1, P8 80, P9 system.io.filenotfoundexception, 
P10 NIL.

I wrote a batch file to run the fax program and it fails with this message. 我写了一个批处理文件来运行传真程序,但此消息失败。

Unhandled Exception: System.IO.FileNotFoundException: Operation failed.
at FAXCOMEXLib.FaxDocumentClass.ConnectedSubmit(FaxServer pFaxServer)

Can anyone explain this behavior to me? 谁能向我解释这种行为?

I can't explain it - but I have a few ideas. 我无法解释-但我有一些想法。

Most of the times, when a program works fine testing it, and doesn't when scheduling it - security is the case. 在大多数情况下,当程序可以对它进行良好的测试时,而在对其进行调度时却不能,因为安全性就是这种情况。 In the context of which user is your program scheduled? 根据您的程序安排了哪个用户? Maybe that user isn't granted enough access. 也许该用户没有被授予足够的访问权限。

Is the resource your programm is trying to access a network drive, that the user running the scheduled task simply haven't got? 您的程序正在尝试访问网络驱动器的资源,是运行计划任务的用户根本没有的资源吗?

检查您为任务设置了正确的工作目录

Is the scheduled task running on the same computer you're developing on, or is it on a dedicated olp server? 预定任务是在您正在开发的同一台计算机上运行还是在专用的olp服务器上运行? It's quite common for paths to change when you change environments, so is the path to the document you're trying to send the same? 当您更改环境时,更改路径很常见,因此您要发送的文档路径是否相同?

I agree with MartinNH. 我同意MartinNH。

Many of these problems root from the fact that you develop while logged in as an administrator in Visual Studio (so the program has all the permissions for execution set properly) but you deploy as a user with lesser privileges. 这些问题中的许多问题源于您在Visual Studio中以管理员身份登录时进行开发的事实(因此该程序具有正确设置所有执行权限的事实),但您以具有较少特权的用户身份进行部署。

Try setting the priveleges of the task scheduler user higher. 尝试将任务计划程序用户的特权设置得更高。

If you are running in Vista, you may find that the elevation is getting in the way. 如果您在Vista中运行,则可能会发现海拔越来越高。 You may need to ensure your task runs as a proper administrator, not as a restricted user. 您可能需要确保任务以适当的管理员身份而不是受限用户身份运行。

When you run a schedule task you can have it run under a user. 运行计划任务时,可以使其在用户下运行。 Verify the user that is running the schedule task has the same rights for the fax resource as you. 验证运行计划任务的用户具有与您相同的传真资源权限。 Which is why you can run it when you double click in Windows explore. 这就是为什么在Windows资源管理器中双击时可以运行它的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM