在任务计划程序中创建事件触发器

时间:2014-04-26 22:26:07

标签: c# scheduled-tasks event-log eventtrigger eventlog-source

我是编程新手,我找到了一个代码,用于在任务调度程序的根文件夹下注册任务。 我有下面的代码,其中有一个方法&#34; eTrigger.SetBasic(&#34;安全&#34;,&#34; Microsoft Windows安全审核。&#34;,4625)&#34;它的作用是创建一个重复的&#34; Log Name&#34;和&#34;日志源&#34;和底线我的代码不起作用。 我想使用eTrigger.GetBasic()或eTrigger.Subscription来解决实际事件日志的代码问题。当我使用eTRigger.GetBasic()将它与我在eTRigger.SetBasic(&#34;安全&#34;,&#34; Microsoft Windows安全审核。&#34;,4625)中提供的参数一起使用时,它会给我错误< / p>

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

到目前为止我的代码:

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

0 个答案:

没有答案
相关问题