Reputation: 69
I'm trying to get all task scheduled from a remote server. I use TaskScheduler 1.1 Type Library that is a COM reference. There is what i tried :
TaskSchedulerClass ts = new TaskSchedulerClass();
ts.Connect(Current_Server, username, domain, password);
IRunningTaskCollection tasks = ts.GetRunningTasks(1);
Console.WriteLine(tasks.Count.ToString());
foreach (IRunningTask task in tasks)
{
Console.WriteLine(task.Name);
}
This run but i didn't get any task in the console.
An another way i tried is using this wrapper : http://taskscheduler.codeplex.com/
Here is the code i use for this solution :
class Task_Get_All_Task
{
public void EnumAllTasks()
{
using (TaskService ts = new TaskService())
EnumFolderTasks(ts.RootFolder);
}
private void EnumFolderTasks(TaskFolder fld)
{
foreach (Task task in fld.Tasks)
ActOnTask(task);
foreach (TaskFolder sfld in fld.SubFolders)
EnumFolderTasks(sfld);
}
private void ActOnTask(Task t)
{
Console.WriteLine(t.Name.ToString());
}
}
With this one i got all task on my own workstation but i dont know how to use it on a remote server.
Upvotes: 0
Views: 3767
Reputation: 69
I was using it the wrong way ... my bad
This work :
var ts = new TaskService(Server, username, domain, password);
foreach (Task task in ts.RootFolder.Tasks)
{
//do things
}
Upvotes: 2