Ste*_*nor -3 .net vb.net schedule task windows-task-scheduler
如何使用 VB.NET 创建计划任务 - 单击按钮时从 vb.net 程序填充计划任务字段?
我目前一无所有,我什至不知道是否有可能。
您必须围绕本机 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");
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13642 次 |
| 最近记录: |