I am trying to see if I can manage a bunch of windows scheduled tasks from an asp.net-mvc site (setting up new tasks, updating frequency of existing tasks, etc) because we want to allow non technical users to update this info (so we want to avoid people having to log into the webserver directly,etc)
I see you can do this from C# in general (links below) but not sure about entitlements, etc that would make it possible to manage via web app.
If its not possible from the web, are there other "remote" options so folks can do this without going in to specific box?
Yes you can, just use the taskschd.dll which can be found in C:\Windows\SysWOW64\ Just reference that to your web app and use it like this
using TaskScheduler;
namespace Test
{
public class Class1
{
public void Test()
{
var taskService = new TaskScheduler.TaskScheduler();
taskService.Connect();
var rootFolder = taskService.GetFolder(@"\");
var registeredTasks = rootFolder.GetTasks(0);
foreach (var registeredTask in registeredTasks)
{
}
}
}
}
To prove to you its running here is screenshot of the running code called from a webpage
As you can see from my machine I grabbed 5 items from my task scheduler.
BTW I created a whole article for you in my blog on how to:
- Get All Scheduled Tasks
- Create/Update Scheduled Tasks
- Delete Scheduled Tasks
in here http://macaalay.com/2013/10/02/programmatic-management-of-scheduled-task/
I would rather to use Quartz.net, it looks more flexible to me rather than the windows task scheduler but the idea could work for both types of schedulers, Take a look to the following case to get the idea and maybe this helps you out:
- Create a WCF
- Consume the WCF service from your asp-net-mvc application
- the WCF will have methods to perform common operations like add and remove tasks
- Store the information for the task into a persistance storage (db, no-sql, xml, etc) or over your cache
- You must have a JOB (from quartz) that reads the database and creates the tasks into the windows box, this job could run every x minutes or y hours
- Use the information and perform a FIFO operation
- Create a form in your asp-net-app for the users to input the tasks and the form will send the information to your wcf service
Edit: you need to have the following in mind: a wcf will give you the state you need to have an "state" to handle the web application tasks, quartz can handle the job to read the database and set up new tasks (quartz or windows scheduler) and the web form is just the front end to handle those operations.
setting up a job in quartz couls be as easy as:
public class ReadDBJob : IJob
{
public void Execute(IJobExecutionContext context)
{
// Do your work to read the database
// and create the tasks that you need
}
}
来源:https://stackoverflow.com/questions/19005691/is-it-possible-to-manage-windows-scheduler-from-an-asp-net-mvc-site-or-other-rem