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 188.8.131.52, P3 48bb146b, P4 consolefaxtest, P5 184.108.40.206, 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?
Read more... Read less...
Check that you set correct working directory for your task
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.
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.
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.