Windows Console App Fails When Run in Task Manager

0

I have a written a .Net console app that scans my Exchange 2007 inbox looking for specific subject text then processes the email body text. It works fine when I launch the app directly but when I set up a scheduled task for the app to run, say, every 10 minutes it crashes (error: "Stopped working") every time when run through taskeng.exe. I've added some console debug statements to see exactly where it fails and it happens right before:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.AutodiscoverUrl("myemail@company.com");

After doing some research it sounds like it could be the user account setting in the scheduler general settings.I checked that and it's set to run when I am logged in with my user credentials, which is what I want. I have other console apps scheduled to run at other times and they have no issue (though they are not using ExchangeService). Does anyone have any ideas?

devedean

Posted 2014-04-24T20:48:10.127

Reputation: 1

Try this

– eyoung100 – 2014-04-24T20:59:11.283

Thanks, but add credentials doesn't work. The app keeps crashing at service.AutodiscoverUrl. Why would it run fine when running it directly versus through a Windows Task Schedule? – devedean – 2014-04-24T22:03:36.947

1You need to add User Credentials to see what user credentials are returned when the Service Starts, my hunch is that your user isn't authorized to run a service. Usually only those users setup as a service or in the Administrators Group can run a service – eyoung100 – 2014-04-24T22:07:52.073

Thanks again @E Carter Young. It sounds like I will have to contact my IT people to get the authorization rather than figure out a workaround. – devedean – 2014-04-24T22:31:04.023

If that is indeed the issue, consider putting your app in your user login script, then it will run each time you login – eyoung100 – 2014-04-24T22:34:11.600

Just so I am totally clear on the issue. Being the fact that this app runs fine when I simply double click it, when I schedule it to run in the Task Scheduler higher authorization is then needed? Is this because of the call to ExchangeService? – devedean – 2014-04-24T22:42:23.797

No any Service requires higher privileges than your user account allows, whether using Exchange or not... Adding UserCredintials to your App would tell you if your authorized or return the error... most likely PermissionDenied – eyoung100 – 2014-04-24T22:44:26.173

No answers