【问题标题】:Create scheduled task using VB.net [duplicate]使用 VB.net 创建计划任务 [重复]
【发布时间】:2014-01-07 18:53:10
【问题描述】:

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

我现在什么都没有,也不知道有没有可能。

【问题讨论】:

    标签: .net vb.net task schedule windows-task-scheduler


    【解决方案1】:

    您必须围绕本机 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");
          }
       }
    }
    

    【讨论】:

    • 是否有可能构建代码来安排一个任务,一旦在 VB 中单击按钮,该任务会将当前登录到计算机的用户添加到本地管理员组 1 小时?然后在一小时后删除。
    • 一切皆有可能,但您需要了解一些 Windows 安全机制
    • codeplex 链接现已失效
    猜你喜欢
    • 2014-03-23
    • 2018-12-01
    • 1970-01-01
    • 2021-08-25
    • 2011-11-15
    • 2015-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多