C# Task Scheduler in Remote Machine
Asked Answered
S

1

6

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.

Stover answered 24/10, 2018 at 19:0 Comment(3)
What is the OS on the remote machine?Teachin
@Teachin It is Windows Server 2003.Stover
taskscheduler.codeplex.com not foundDisputatious
T
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.

Teachin answered 24/10, 2018 at 19:13 Comment(3)
Thank you Sean. I might have overlooked it. Any workarounds for this..?? I really need to set this schedule up in the server.Stover
@KarthikeyanNatarajan updated answer with possible work aroundTeachin
I tried the Schtasks to set up the scheduled task in the remote server however it produced the ERROR - The request is not supported. The format that I used was : schtasks /run /s servername.us.domainname /u username /p password /I /TN "Test"Stover

© 2022 - 2024 — McMap. All rights reserved.