I am trying to create a program that will automatically keep track of the windows task scheduler and will notify me via email if a ny of the scheduled task fails to launch. I am C# as the programming language. I've checked various references but haven't been able to achieve this. Can anyone please provide me any reference or suggestion as to how I can access the log and check if any task launch has failed?
Here's my code:
EventLog demoLog = new EventLog();
demoLog.Source="Microsoft-Windows-TaskScheduler/Operational";
try
{
EventLogEntryCollection entries = demoLog.Entries;
foreach (EventLogEntry entry in entries)
{
Console.WriteLine("Level: {0}", entry.EntryType);
Console.WriteLine("Event id: {0}", entry.InstanceId);
Console.WriteLine("Message: {0}", entry.Message);
Console.WriteLine("Source: {0}", entry.Source);
Console.WriteLine("Date: {0}", entry.TimeGenerated);
Console.WriteLine("--------------------------------");
}
}
catch(Exception e)
{
Console.Write(e.Message);
}
Check this link.
They use there an EventlogReader
to get the information. Maybe it help. I managed to read the events from my computer using it.