Get list of scheduled task in the local machine

  • Thread starter Thread starter odylicforce
  • Start date Start date
O

odylicforce

Guest
Hi,



I am trying to schedule a task via c# code(winforms). But before creating I would like to check whether a task of the same name already exists. I am trying to get a list of tasks using schtasks /query. But it gives other information as well ,like HostName, Status etc. I need only the list of TaskNames.

I tried the code as shown below. The strOutput shows headers, status, hostname and next time run along with TaskName. I need only Tasknames. Help would be appreciated.




private

void button1_Click(object sender, EventArgs e)

{


ProcessStartInfo psi = new ProcessStartInfo("SCHTASKS", "/QUERY /fo table");

psi.RedirectStandardOutput =
true;

psi.UseShellExecute =
false;

Process p = Process.Start(psi);


p.OutputDataReceived +=
new DataReceivedEventHandler(p_OutputDataReceived);

p.BeginOutputReadLine();


}




void p_OutputDataReceived(object sender, DataReceivedEventArgs e)

{

//string str = "";


strOutput += e.Data+
",";


}

private void button2_Click(object sender, EventArgs e)

{

label1.Text = strOutput;

}


Continue reading...
 
Back
Top