在任务计划程序中创建事件触发器 [英] Creating Event Trigger in Task Scheduler

查看:808
本文介绍了在任务计划程序中创建事件触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编程新手,我找到了一个代码,用于在任务调度程序的根文件夹下注册任务。

我有以下代码,其中有一个方法 eTrigger.SetBasic(安全,Microsoft Windows安全审核。,4625)它的作用是创建一个重复的日志名称和日志源和底线我的代码不起作用。

我想使用 eTrigger.GetBasic( ) eTrigger.Subscription 将我的代码发送到实际的事件日志。当我使用eTRigger.GetBasic()它与我在 eTRigger.SetBasic(安全,Microsoft Windows安全审核。,4625)中提供的参数时,它给了我错误



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



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.SetBasic("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.GetBasic() or eTrigger.Subscription to address my code to the actual event logs. When I use eTRigger.GetBasic() it with the arguments I am giving in eTRigger.SetBasic("Security", "Microsoft Windows security auditing.", 4625) it gives me error

Can someone fix this code for me?

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

推荐答案

这篇关于在任务计划程序中创建事件触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆