簡體   English   中英

無法使用c sharp創建基於事件的任務計划程序

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM