dahall / TaskScheduler

Provides a .NET wrapper for the Windows Task Scheduler. It aggregates the multiple versions, provides an editor and allows for localization.
MIT License
1.21k stars 191 forks source link

asp.net issue with findTask #859

Closed focusede closed 3 years ago

focusede commented 3 years ago

Hi, first off thank you for this wrapper. It seems to do exactly what I need, which is missing in my life.

On a Win2016 server, I have manually created a task which runs an exe. I am hoping just to trigger that task from my asp.net application.

using (var ts = new TaskService()) { // This will find it even if its down in a folder. var t = ts.FindTask(sTaskName); if (t != null) { t.Run(); {

So what is happening is t is always null. I have placed the task in the root folder just in case to no avail. I have searched but am hoping you can point me to the right way to execute this task. On a local machine (win10) I was able to run my simple task. Is there a step by step guide somewhere describing what must be done for the task to be found and run?

focusede commented 3 years ago

sorry Github crashed on my submission.

dahall commented 3 years ago

I don't know if there is a step-by-step set of instructions, but basically you have a permissions problem. The Task Scheduler is very picky about own, view, edit, run permissions. You need to make sure that the ASP.NET account has access to the task created by the other account. Look at the security of the task (warning: poor documentation from Microsoft on this one and a lot of trial and error) and which account you're using to create the initial task.

As a side-note, I recommend not using using (var ts = new TaskService()) for the default TaskService access. Use TaskService.Instance in place of ts (e.g. var t = TaskService.Instance.FindTask(sTaskName);).

dahall commented 3 years ago

One thought is to create the task using the ASP.NET identity. Here you would use the TaskService constructor to pass in those credentials. Then create the task. Then, in your site code, you can use TaskService.Instance (since you're already running under those credentials) and you will see the task you created.

dahall commented 3 years ago

Please reopen if your issue is still unresolved.