how to get task from remote server

Jul 25, 2012 at 9:36 AM
Edited Jul 25, 2012 at 9:37 AM

Hi ALL

I Want to call remotely windows task scheduler for this i am using Microsoft.Win32.TaskScheduler.dll and created object of TaskService class like

TaskService 01_server = getTaskService("\\\\123.123.222.222", "administrator", "domain1", "pwd0", false);
TaskService 02_server = getTaskService("\\\\123.122.222.222", "administrator", "domain2", "pwd1", false);

and bind task to grodview

for server 01_serve
DataTable dataTable = new DataTable();
dataTable.Columns.Add("TaskName");
dataTable.Columns.Add("TaskSchedule");
dataTable.Columns.Add("TaskNextRun");
dataTable.Columns.Add("TaskLastRun");
dataTable.Columns.Add("State");
dataTable.AcceptChanges();

DataRow dataRow;
StringBuilder sbTaskSchedule = new StringBuilder();

Version ver = 01_server .HighestSupportedVersion;
bool newVer = (ver >= new Version(1, 2));

TaskFolder tf = 01_serve.RootFolder;


int ctaskNx =01_serve.RootFolder.Tasks.Count;

for (int i = 0; i < ctaskNx; i++)
{

m_Task = 01_serve.RootFolder.Tasks[i];

string strFileNamePath = m_Task.Definition.Actions.ToString().Trim();

if (strFileNamePath.Contains(".vbs"))
{
dataRow = dataTable.NewRow();
dataRow["TaskName"] = m_Task.Name.ToString().Trim();
dataRow["TaskNextRun"] = m_Task.NextRunTime.ToString().Trim();
dataRow["TaskLastRun"] = m_Task.LastRunTime.ToString().Trim();
dataRow["State"] = m_Task.State.ToString().Trim();
dataTable.Rows.Add(dataRow);
dataTable.AcceptChanges();
}
}

for server 02_serve

Version ver = 02_server .HighestSupportedVersion;
bool newVer = (ver >= new Version(1, 2));

TaskFolder tf = 02_server.RootFolder;


int ctaskNx = 02_server.RootFolder.Tasks.Count;

for (int i = 0; i < ctaskNx; i++)
{

m_Task = 02_server.RootFolder.Tasks[i];

string strFileNamePath = m_Task.Definition.Actions.ToString().Trim();

if (strFileNamePath.Contains(".vbs"))
{
dataRow = dataTable.NewRow();
dataRow["TaskName"] = m_Task.Name.ToString().Trim();
dataRow["TaskNextRun"] = m_Task.NextRunTime.ToString().Trim();
dataRow["TaskLastRun"] = m_Task.LastRunTime.ToString().Trim();
dataRow["State"] = m_Task.State.ToString().Trim();
dataTable.Rows.Add(dataRow);
dataTable.AcceptChanges();
}
}

but i am not able to get task from remote server
please guide me where i am wrong

thanks
vinod