How to get the last run time of a specific task

Jul 16, 2014 at 7:37 AM
This is what i have tried but i have a few question to ask
1) Where do we get the taskpath from ? The scheduler is running an application every 1 hour. Is the path equals to the path of the application ?

2)Can i get the last run time exactly like the one displayed in the windows task scheduler because i did not create a task dynamically using this library

string lastruntime;
using (TaskService ts = new TaskService())
{
    Microsoft.Win32.TaskScheduler.Task task = ts.GetTask(@"C:\Program Files     (x86)\Google\Update\GoogleUpdate.exe");
    if (task!= null)
    {
           lastruntime = task.LastRunTime.ToString();
     }
}
Coordinator
Jul 17, 2014 at 2:32 PM
  1. The path needed by the GetTask method is the full folder hierarchy plus the task name. When looking in the system Task Scheduler applet, on systems Vista or later you will see a set of folders just like the file system. For example, the path to the single task in the Bluetooth folder under Windows 8 is "\Microsoft\Windows\Bluetooth\UninstallDeviceTask".
  2. Since this library is simply a wrapper around the core Microsoft library, tasks created by either should be available to either. Your code is correct for retrieving the last run time of a named task.
Marked as answer by dahall on 7/17/2014 at 7:32 AM