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

<pre><code>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.
</code></pre>

<p>I wrote a batch file to run the fax program and it fails with this message.</p>

<pre><code>Unhandled Exception: System.IO.FileNotFoundException: Operation failed.
at FAXCOMEXLib.FaxDocumentClass.ConnectedSubmit(FaxServer pFaxServer)
</code></pre>

<p>Can anyone explain this behavior to me?</p>

[{'answer_id': 37199, 'author': 'aku', 'author_id': 1196, 'author_profile': 'https://Stackoverflow.com/users/1196', 'pm_score': 0, 'selected': False, 'text': '<p>Check that you set correct working directory for your task</p>\n'}, {'answer_id': 37200, 'author': 'Glenn Slaven', 'author_id': 2975, 'author_profile': 'https://Stackoverflow.com/users/2975', 'pm_score': 0, 'selected': False, 'text': "<p>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?</p>\n"}, {'answer_id': 37202, 'author': 'MartinHN', 'author_id': 2972, 'author_profile': 'https://Stackoverflow.com/users/2972', 'pm_score': 4, 'selected': True, 'text': "<p>I can't explain it - but I have a few ideas.</p>\n\n<p>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.</p>\n\n<p>Is the resource your programm is trying to access a network drive, that the user running the scheduled task simply haven't got?</p>\n"}, {'answer_id': 37215, 'author': 'Jon Limjap', 'author_id': 372, 'author_profile': 'https://Stackoverflow.com/users/372', 'pm_score': 0, 'selected': False, 'text': '<p>I agree with MartinNH.</p>\n\n<p>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.</p>\n\n<p>Try setting the priveleges of the task scheduler user higher.</p>\n'}, {'answer_id': 37254, 'author': '1800 INFORMATION', 'author_id': 3146, 'author_profile': 'https://Stackoverflow.com/users/3146', 'pm_score': 0, 'selected': False, 'text': '<p>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.</p>\n'}, {'answer_id': 37802, 'author': 'David Basarab', 'author_id': 2469, 'author_profile': 'https://Stackoverflow.com/users/2469', 'pm_score': 0, 'selected': False, 'text': '<p>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.</p>\n'}]
['https://Stackoverflow.com/questions/37189', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1203/']