Access denied while deleting the task from Windows Task Scheduler in C#

Abhinav Mutreja 1 Reputation point
2021-06-21T09:20:27+00:00

I am trying to delete the task from the windows task scheduler in c# using below code -

using TaskService ts = new TaskService();
ts.RootFolder.DeleteTask(TaskName);

It is throwing below error. Kindly help.

Access is denied. (0x80070005 (E_ACCESSDENIED)) -- at Microsoft.Win32.TaskScheduler.V2Interop.ITaskFolder.DeleteTask(String Name, Int32 flags)

Developer technologies C#
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 90,521 Reputation points
    2021-06-21T09:49:40.61+00:00

    This works for me with
    TaskScheduler 1.1 Type Library
    =>

    ITaskService ts = new TaskScheduler.TaskScheduler();
    try
    {
        ts.Connect(null, null, null, null);
        ITaskFolder rootFolder = ts.GetFolder(string.Empty);
        rootFolder.DeleteTask("MyTask", 0);                   
    }
    catch (Exception ex)
    {
        System.Windows.Forms.MessageBox.Show("Error : " + ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        return;
    }
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.