简体   繁体   中英

C# Task Scheduler in Remote Machine

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM