0

我是编程新手,我找到了在任务调度程序的根文件夹下注册任务的代码。我有下面的代码,其中有一个方法“eTrigger.SetBasic("Security", "Microsoft Windows security auditing.", 4625)" 它的作用是创建一个重复的“日志名称”和“日志源”和底部行我的代码不起作用。我想使用 eTrigger.GetBasic() 或 eTrigger.Subscription 将我的代码寻址到实际的事件日志。当我将 eTRigger.GetBasic() 与我在 eTRigger.SetBasic("Security", "Microsoft Windows security auditing.", 4625) 中给出的参数一起使用时,它给了我错误

有人可以为我修复此代码吗?

到目前为止我的代码:

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);
        }
    }
}
4

0 回答 0