Create scheduled task using VB.net [duplicate]

萝らか妹 提交于 2019-12-20 08:08:11

问题


How do I create a scheduled task using VB.NET - Populating Scheduled Task fields from vb.net program on button click?

I have nothing at the moment, nor do I even know if it is possible.


回答1:


You have to create wrappers around the native COM interfaces. If you don't want to do it yourself, you can use this library https://taskscheduler.codeplex.com

using System;
using Microsoft.Win32.TaskScheduler;

class Program
{
   static void Main(string[] args)
   {
      // Get the service on the local machine
      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
         td.Triggers.Add(new DailyTrigger { DaysInterval = 2 });

         // Create an action that will launch Notepad whenever the trigger fires
         td.Actions.Add(new ExecAction("notepad.exe", "c:\\test.log", null));

         // Register the task in the root folder
         ts.RootFolder.RegisterTaskDefinition(@"Test", td);

         // Remove the task we just created
         ts.RootFolder.DeleteTask("Test");
      }
   }
}


来源:https://stackoverflow.com/questions/20677722/create-scheduled-task-using-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!