Kaashyap Sarma
Kaashyap Sarma

Reputation: 11

Check the status of a schedule task in a remote server using c#

 ScheduledTasks st = new ScheduledTasks(ServerName);

 string[] taskNames = st.GetTaskNames();
 List<string> jobs = new List<string>(taskNames);

 if(jobs.Contains(taskName))
 {
     return true;
 }

 st.Dispose();

    }

i am trying to get the list of all scheduled tasks running in a remote server.i have downloaded the takschd.dll and microsoft.win32.taskscheduler dll as well.the references have been added.and yet the error says "TYPE OR NAMESPACE SCHEDULEDTASKS COULD NOT BE FOUND".How to rectify this?

Upvotes: 0

Views: 4295

Answers (1)

dahall
dahall

Reputation: 348

Using the NuGet package TaskScheduler:

using Microsoft.Windows.TaskScheduler;
using System.Linq;

using (var ts = new TaskService(@"\\RemoteServerName", "AuthUserName", "AuthDomName", "UserPassword", false))
{
    return ts.GetRunningTasks(true).FirstOrDefault(t => t.Name == "taskName") != null;
}

Upvotes: 2

Related Questions