tags:

views:

1065

answers:

7

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?

A: 

Check that you set correct working directory for your task

aku
A: 

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?

Glenn Slaven
+5  A: 

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?

MartinHN
A: 

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.

Jon Limjap
A: 

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.

1800 INFORMATION
A: 

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.

David Basarab
A: 

I'm having the same kind of problem, but I'm running program and task as administrator...the problem is even bigger...if the task runs while I'm logged in, it runs ok, if I logout and let the task trigger while I'm logged out, it can't find the file (and even then, I know I'm running the program as domain administrator - print message). Any clues?? :(