使用VB.net创建计划任务 [英] Create scheduled task using VB.net

查看:84
本文介绍了使用VB.net创建计划任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用VB.NET创建计划任务-单击按钮时从vb.net程序填充计划任务字段?

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.

推荐答案

您必须围绕本机COM接口创建包装器.如果您不想自己做,可以使用此库 https://taskscheduler.codeplex.com

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");
      }
   }
}

这篇关于使用VB.net创建计划任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆