【发布时间】:2014-01-07 18:53:10
【问题描述】:
如何使用 VB.NET 创建计划任务 - 单击按钮时从 vb.net 程序填充计划任务字段?
我现在什么都没有,也不知道有没有可能。
【问题讨论】:
标签: .net vb.net task schedule windows-task-scheduler
如何使用 VB.NET 创建计划任务 - 单击按钮时从 vb.net 程序填充计划任务字段?
我现在什么都没有,也不知道有没有可能。
【问题讨论】:
标签: .net vb.net task schedule windows-task-scheduler
您必须围绕本机 COM 接口创建包装器。如果不想自己做,可以使用这个库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");
}
}
}
【讨论】: