[英]not able to create Event based Task Scheduler using c sharp
我尝试使用c sharp创建窗口任务。 我制作了代码,但代码不起作用,我得到运行时expcetionn。 它是一个基于事件的任务调度程序。 我正在尝试安排一个任务,它将在系统中更改WIFI网络时调用。
我试图检查微软以及外面的很多文章。 我不想使用像“Quartz”那样的任何第三方库。
using (TaskService ts = new TaskService())
{
//Create a new task definition and assign properties
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "Git Config Details";
// Create a trigger that will fire the task at this time every other day
EventTrigger Etrigger = new EventTrigger("Mircosoft-Windows-NetworkProfile/Opertaional", "NetworkProfile", 10002);
Etrigger.Enabled = true;
td.Triggers.Add(Etrigger);
// Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add(new ExecAction(@"C:\projects\Own\powershell\first.bat"));
// Register the task in the root folder
ts.RootFolder.RegisterTaskDefinition("Duplicate", td, TaskCreation.CreateOrUpdate, "NT AUTHORITY\\NETWORKSERVICE", null,
TaskLogonType.ServiceAccount);
}
我的错误一些拼写错误导致了这个问题。 我的上述代码中的Microsoft和操作拼写错误。
这是现在处于工作状态的新代码。
using (TaskService ts = new TaskService())
{
//Create a new task definition and assign properties
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "Duplicate";
// Create a trigger that will fire the task at this time every other day
EventTrigger Etrigger = new EventTrigger("Microsoft-Windows-NetworkProfile/Operational", "Microsoft-Windows-NetworkProfile", 10002);
Etrigger.Enabled = true;
td.Triggers.Add(Etrigger);
// Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add(new ExecAction(@"C:\projects\Own\powershell\first.bat"));
// Register the task in the root folder
ts.RootFolder.RegisterTaskDefinition("Duplicate", td, TaskCreation.CreateOrUpdate, "NT AUTHORITY\\NETWORKSERVICE", null,
TaskLogonType.ServiceAccount);
}
感谢所有人对我的帖子发表评论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.