简体   繁体   中英

Task Scheduler - When the event is added to the event log the created task not running

Here is the code that I used to create task and bind it to event log, after doing some action I can see in event logs that new event log was created, but task not stared, what was done incorrect here ?

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" should be "Microsoft-Windows-AppXDeployment-Server" windows event viewer for some reason it doesn't show the full name.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM