I am new to programming and I have found a code to register a task under root folder in task scheduler.
I have the below code in which there is a method "eTrigger.SetBa sic("Security", "Microsoft Windows security auditing.", 4625)" what it does is it creates a duplicate "Log Name" and "Log Source" and bottom line my code does not work.
I want to use eTrigger.GetBas ic() or eTrigger.Subscr iption to address my code to the actual event logs. When I use eTRigger.GetBas ic() it with the arguments I am giving in eTRigger.SetBas ic("Security", "Microsoft Windows security auditing.", 4625) it gives me error
Can someone fix this code for me?
I have the below code in which there is a method "eTrigger.SetBa sic("Security", "Microsoft Windows security auditing.", 4625)" what it does is it creates a duplicate "Log Name" and "Log Source" and bottom line my code does not work.
I want to use eTrigger.GetBas ic() or eTrigger.Subscr iption to address my code to the actual event logs. When I use eTRigger.GetBas ic() it with the arguments I am giving in eTRigger.SetBas ic("Security", "Microsoft Windows security auditing.", 4625) it gives me error
Can someone fix this code for me?
Code:
class Program
{
static void Main(string[] args)
{
using (TaskService ts = new TaskService())
{
// Create a new task definition and assign properties
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "Does something";
// Create a trigger that will fire the task at this time every other day
// whether user is logged on or not
EventTrigger eTrigger = (EventTrigger)td.Triggers.Add(new EventTrigger());
EventLog securityLog = new EventLog("Security", System.Environment.MachineName);
//this is where I see problem. I want to use eTrigger.GetBasic
eTrigger.SetBasic("Security", "Microsoft Windows security auditing.", 4625);
eTrigger.Enabled = true;
eTrigger.ExecutionTimeLimit = TimeSpan.Zero;
// Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add(new ExecAction(@"C:\Windows\notepad.exe"));
// Register the task in the root folder
ts.RootFolder.RegisterTaskDefinition("test", td);
}
}
}