任务计划程序 - 当事件添加到事件日志时创建的任务不是 运行
Task Scheduler - When the event is added to the event log the created task not running
这是我用来创建任务并将其绑定到事件日志的代码,在执行一些操作后,我可以在事件日志中看到创建了新的事件日志,但没有启动任务,这里做错了什么?
public void CreateTaskSchedulerTask(Trigger trigger, string name,string description, string path, string arguments, string workingDirectory = null)//"Remove unnecessary dependencies"
{
TaskDefinition td = TaskService.Instance.NewTask();
td.Triggers.Add(trigger);
//td.Principal.LogonType = TaskLogonType.InteractiveToken;
td.RegistrationInfo.Description = description;
td.Actions.Add(new ExecAction(path/*"notepad.exe"*/, arguments/*"c:\test.log"*/, workingDirectory));
td.Settings.Enabled = true;
td.Settings.Priority = System.Diagnostics.ProcessPriorityClass.Normal;
td.Settings.StartWhenAvailable = true;
td.Settings.DisallowStartIfOnBatteries = false;
td.Settings.StopIfGoingOnBatteries = false;
// td.Settings.RunOnlyIfLoggedOn = false;
TaskService.Instance.RootFolder.RegisterTaskDefinition(name, td);
}
public EventTrigger CreateEventTrigger(string log, string source, int? eventId)//"Microsoft-Windows-AppXDeploymentServer/Operational", "AppXDeployment-Server", 400
{
return new EventTrigger(log, source, eventId);
}
"AppXDeployment-Server" 应该是 "Microsoft-Windows-AppXDeployment-Server" windows 事件查看器由于某种原因它没有显示全名。
这是我用来创建任务并将其绑定到事件日志的代码,在执行一些操作后,我可以在事件日志中看到创建了新的事件日志,但没有启动任务,这里做错了什么?
public void CreateTaskSchedulerTask(Trigger trigger, string name,string description, string path, string arguments, string workingDirectory = null)//"Remove unnecessary dependencies"
{
TaskDefinition td = TaskService.Instance.NewTask();
td.Triggers.Add(trigger);
//td.Principal.LogonType = TaskLogonType.InteractiveToken;
td.RegistrationInfo.Description = description;
td.Actions.Add(new ExecAction(path/*"notepad.exe"*/, arguments/*"c:\test.log"*/, workingDirectory));
td.Settings.Enabled = true;
td.Settings.Priority = System.Diagnostics.ProcessPriorityClass.Normal;
td.Settings.StartWhenAvailable = true;
td.Settings.DisallowStartIfOnBatteries = false;
td.Settings.StopIfGoingOnBatteries = false;
// td.Settings.RunOnlyIfLoggedOn = false;
TaskService.Instance.RootFolder.RegisterTaskDefinition(name, td);
}
public EventTrigger CreateEventTrigger(string log, string source, int? eventId)//"Microsoft-Windows-AppXDeploymentServer/Operational", "AppXDeployment-Server", 400
{
return new EventTrigger(log, source, eventId);
}
"AppXDeployment-Server" 应该是 "Microsoft-Windows-AppXDeployment-Server" windows 事件查看器由于某种原因它没有显示全名。