Creating Scheduled Tasks
You can use Task Scheduler Managed Wrapper:
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");
}
}
}
Alternatively you can use native API or go for Quartz.NET. See this for details.
VBScript for creating a scheduled task
There's no need for cmd
. Schtasks
is its own executable, not a command within cmd
. And for your quoted params, just use two quotes.
For example:
wShell.Run "SchTasks /Create /SC WEEKLY /D MON,TUE,WED,THU,FRI /TN ""Test Task"" /TR ""C:\test.bat"" /ST 16:30", 0
Related Topics
Get List of Connected Usb Devices
Why Is Dictionary Preferred Over Hashtable in C#
Get the Correct Week Number of a Given Date
Wix Installer Msi Not Installing the Winform App Created With Visual Studio 2017
Why Doesn't C# Infer My Generic Types
Finding Holes in 2D Point Sets
Assign Bitmapimage from Resources.Resx to Image.Source
A Generic Error Occurred in Gdi+, Jpeg Image to Memorystream
When Is It Acceptable to Call Gc.Collect
The Foreach Identifier and Closures
Catch Multiple Exceptions At Once
How to Get the List of Open File Handles by Process in C#
Convert Linq Expression "Obj =≫ Obj.Prop" into "Parent =≫ Parent.Obj.Prop"