简体   繁体   中英

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. When I step through the program in Visual Studio it works fine. When I double click on the program in Windows Explorer it works fine. When I setup a Windows scheduled task to run the program it fails with this in the event log.

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? 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.

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.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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