C# Task Scheduler in Remote Machine

5

I'm trying to set up a program that would create a task schedule in a remote server. The following code works fine for local machine however when I try it with the remote server, it throws up the following error.

System.Runtime.InteropServices.COMException: 'The request is not supported. (Exception from HRESULT: 0x80070032)'

void SetupDailyTask()
    {
        using (TaskService ts = new TaskService("servername.us.xxxxxdomain.com",
            @"domainname\username","domainname","password"))
        {
            //Task tsk = ts.GetTask("DailyTask");
            //if (tsk != null) { ts.RootFolder.DeleteTask("DailyTask"); }

            //DateTime dt = DateTime.Now;
            //TimeSpan tsp = new TimeSpan(12, 44, 0);
            //dt = dt.Date + tsp;
            //ts.Execute("notepad.exe").Once().Starting(dt).AsTask("DailyTask");
        }
    }

I've already tested the credentials, server name etc and they work just fine with the Remote Desktop Connection. I'm using the Microsoft.Win32.TaskScheduler namespace. Any help with this is much appreciated.

c#
taskscheduler
taskservice
asked on Stack Overflow Oct 24, 2018 by Karthikeyan Natarajan • edited Oct 24, 2018 by Karthikeyan Natarajan

1 Answer

3

According to the Microsoft documentation, this is only supported on Windows Server 2008 or newer.

One option I found was provided by Microsoft, but I've not tried it.

answered on Stack Overflow Oct 24, 2018 by UnhandledExcepSean • edited Oct 24, 2018 by UnhandledExcepSean

User contributions licensed under CC BY-SA 3.0