Recently I was trouble shooting an ASP.NET COTS package that utilizes the Windows Task Scheduler to schedule and execute long running tasks asynchronously for users. While troubleshooting, I discovered that the application was using an open source managed wrapper to access the Windows task scheduler API (COM based API from Microsoft). More information on this managed wrapper may be found here:
http://taskscheduler.codeplex.com/documentation
If you need to interact with the Windows Task Scheduler from managed code, this looks like a great way to do it. The API is light-weight and appears to be extremely easy to use.
I also learned a couple of important “safety tips” while troubleshooting the use of this API:
- Initially I added the user under which the task would run to the local admin group of the machine. This allowed the task to run without an issue, but it didn’t seem necessary (or prudent) to run the tasks as an administrative user. However, when I removed the service account from the administrator group it immediately failed. I was able to remove this user from the admin group by giving it the privilege “log on as a batch”. I followed the instructions in this post: http://social.technet.microsoft.com/Forums/en-US/winservergen/thread/83741b68-a69a-4b2d-a5a7-64b69e15868b/
- I also noticed that when I removed the service account from the admin group that, under my individual account, I was no longer able to right-click and run the tasks created (and owned) by the service account in the task scheduler UI on the server. I believe this is because the administrator account only has rights to run tasks created by system or other administrators. I modified the ACL security on the c:\windows\system32\tasks folder to allow administrators full access to all tasks, which resolved the issue.
- There is an option to set created tasks to automatically be deleted from the scheduler after X number of days. Setting this to 0 days caused them to be deleted immediately.
Have fun scheduling tasks in .NET!