2013-12-19 68 views
-3

如何使用VB.NET創建計劃任務 - 在按鈕單擊時從vb.net程序填充計劃任務字段?使用VB.net創建計劃任務

我目前沒有任何東西,我也不知道它是否可能。

+1

謝謝,但多數民衆贊成在真正的即時通訊尋找。 –

回答

3

你必須創建本地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"); 
     } 
    } 
} 
+1

一旦按鈕在VB中單擊,是否有可能構建代碼來安排一個任務,該任務將當前登錄到計算機的用戶添加到本地管理員組1小時?然後在一小時後刪除。 –

+0

一切皆有可能,但您需要了解一些Windows安全機制 – meziantou

+0

codeplex鏈接現已停止 – Smith