本文整理汇总了C#中Microsoft.Win32.TaskScheduler.TaskService.NewTask方法的典型用法代码示例。如果您正苦于以下问题:C# TaskService.NewTask方法的具体用法?C# TaskService.NewTask怎么用?C# TaskService.NewTask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Win32.TaskScheduler.TaskService
的用法示例。
在下文中一共展示了TaskService.NewTask方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
TaskService ts = new TaskService();
var tasks = ts.FindAllTasks(new Regex(string.Empty));
var task = ts.GetTask("Elevate");
TaskDefinition td = ts.NewTask();
td.Principal.RunLevel = TaskRunLevel.Highest;
//td.Triggers.AddNew(TaskTriggerType.YourDesiredSchedule);
td.Triggers.AddNew(TaskTriggerType.Registration);
//td.Actions.Add(new ExecAction("Path Of your Application File", null));
td.Actions.Add(new ExecAction(@"E:\StructuresSrc\Kit\bin\gacutil.exe", "/nologo /u \"Tekla.Logging, Version=99.1\""));
ts.RootFolder.RegisterTaskDefinition("GatUtil", td);
td.Actions.Add(new ExecAction(@"E:\StructuresSrc\MSBuild\MSBuild\MSBuildTasks\Elevate.exe", "E:\\StructuresSrc\\Kit\\bin\\gacutil.exe /nologo /u \"Tekla.Logging, Version=99.1\""));
ts.RootFolder.RegisterTaskDefinition("Elevate", td);
ts.RootFolder.DeleteTask("Elevate", false);
}
示例2: AddTask
public void AddTask(int min, int hour, bool restart)
{
var taskService = new TaskService();
//Create task definition
var taskDefinition = taskService.NewTask();
taskDefinition.RegistrationInfo.Description = min + "@" + hour + "@" + ((restart) ? "r" : "s");
taskDefinition.Principal.UserId = "SYSTEM";
var trigger = new DailyTrigger
{
StartBoundary = DateTime.Today + TimeSpan.FromHours(hour) + TimeSpan.FromMinutes(min)
};
taskDefinition.Triggers.Add(trigger);
//Create task action
var fileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"Power.exe");
taskDefinition.Actions.Add(restart
? new ExecAction(fileName, "reboot \"This computer is going to reboot.\"")
: new ExecAction(fileName, "shutdown \"This computer is going to shutdown to save power.\""));
taskDefinition.Settings.AllowDemandStart = false;
taskDefinition.Settings.DisallowStartIfOnBatteries = false;
taskDefinition.Settings.DisallowStartOnRemoteAppSession = false;
taskDefinition.Settings.StopIfGoingOnBatteries = false;
taskService.RootFolder.RegisterTaskDefinition(@"FOG\" + taskDefinition.RegistrationInfo.Description,
taskDefinition);
taskService.Dispose();
}
示例3: EditorTest
internal static void EditorTest(TaskService ts, System.IO.TextWriter output, params string[] arg)
{
try
{
const string taskName = "Test";
// Create a new task definition and assign properties
TaskDefinition td = ts.NewTask();
/*td.RegistrationInfo.Description = "Test for XP SP3";
td.RegistrationInfo.Author = "incaunu";*/
td.Triggers.Add(new DailyTrigger() { StartBoundary = new DateTime(2014, 1, 15, 9, 0, 0), EndBoundary = DateTime.Today.AddMonths(1) });
/*EventTrigger eTrig = new EventTrigger("Security", "VSSAudit", 25);
eTrig.ValueQueries.Add("Name", "Value");
td.Triggers.Add(eTrig);*/
//td.Actions.Add(new ExecAction("cmd.exe", "/c \"date /t > c:\\cmd.txt\""));
EmailAction ea = (EmailAction)td.Actions.Add(new EmailAction("Hi", "[email protected]", "[email protected]; [email protected]", "<p>How you been?</p>", "smtp.codeplex.com"));
ea.HeaderFields.Add("reply-to", "[email protected]");
ea.Attachments = new object[] { (string)new TemporaryScopedFile(), (string)new TemporaryScopedFile() };
//WriteXml(td, taskName);
Task t = ts.RootFolder.RegisterTaskDefinition(taskName, td); //, TaskCreation.CreateOrUpdate, "SYSTEM", null, TaskLogonType.ServiceAccount);
System.Converter<DateTime, string> d = delegate(DateTime ints) { return ints == DateTime.MinValue ? "Never" : ints.ToString(); };
output.Write("***********************\r\nName: {0}\r\nEnabled: {1}\r\nLastRunTime: {2}\r\nState: {3}\r\nIsActive: {4}\r\nNextRunTime: {5}\r\nShouldHaveRun: {6}\r\nTriggerStart: {7}\r\nTriggerEnd: {8}\r\n",
t.Name, t.Enabled, d(t.LastRunTime), t.State, t.IsActive, t.NextRunTime, d(t.LastRunTime), t.Definition.Triggers[0].StartBoundary, t.Definition.Triggers[0].EndBoundary);
WriteXml(t);
// Register then show task again
while (DisplayTask(ts.GetTask(taskName), true) != null)
{
Task t2 = editorForm.Task;
output.Write("***********************\r\nName: {0}\r\nEnabled: {1}\r\nLastRunTime: {2}\r\nState: {3}\r\nIsActive: {4}\r\nNextRunTime: {5}\r\nShouldHaveRun: {6}\r\nTriggerStart: {7}\r\nTriggerEnd: {8}\r\n",
t2.Name, t2.Enabled, t2.LastRunTime, t2.State, t2.IsActive, t2.NextRunTime, t2.LastRunTime, t2.Definition.Triggers[0].StartBoundary, t2.Definition.Triggers[0].EndBoundary);
}
// Remove the task we just created
ts.RootFolder.DeleteTask(taskName);
}
catch (Exception ex)
{
output.WriteLine(ex.ToString());
}
}
示例4: TaskShedulerWrapper_Dev2TaskSettings_PassThrough
public void TaskShedulerWrapper_Dev2TaskSettings_PassThrough()
{
var service = new TaskService();
var task =service.NewTask();
var settings = new Dev2TaskSettings(task.Settings);
settings.AllowDemandStart = true;
settings.DeleteExpiredTaskAfter = new TimeSpan(2);
settings.AllowHardTerminate = true;
settings.DisallowStartOnRemoteAppSession = true;
settings.Enabled = false;
settings.ExecutionTimeLimit = new TimeSpan(3);
settings.Hidden = true;
settings.MultipleInstances = TaskInstancesPolicy.IgnoreNew;
settings.Priority = ProcessPriorityClass.High;
settings.RestartCount = 3;
settings.StartWhenAvailable = false;
settings.WakeToRun = true;
var native = task.Settings;
Assert.AreEqual(settings.AllowDemandStart,native.AllowDemandStart);
Assert.AreEqual(settings.AllowHardTerminate,native.AllowHardTerminate);
Assert.AreEqual(settings.DeleteExpiredTaskAfter,native.DeleteExpiredTaskAfter);
Assert.AreEqual(settings.DisallowStartOnRemoteAppSession,native.DisallowStartIfOnBatteries);
Assert.AreEqual(settings.Enabled,settings.Enabled);
Assert.AreEqual(settings.ExecutionTimeLimit,native.ExecutionTimeLimit);
Assert.AreEqual(settings.ExecutionTimeLimit,native.ExecutionTimeLimit);
Assert.AreEqual(settings.Hidden,native.Hidden);
Assert.AreEqual(settings.MultipleInstances,native.MultipleInstances);
Assert.AreEqual(settings.RestartCount,native.RestartCount);
Assert.AreEqual(settings.Priority,native.Priority);
Assert.AreEqual(settings.RestartInterval,native.RestartInterval);
Assert.AreEqual(settings.StartWhenAvailable,native.StartWhenAvailable);
Assert.AreEqual(settings.WakeToRun,native.WakeToRun);
}
示例5: CreateDefaultTask
/// <summary>
/// Creates default task in the Task Scheduler service
/// </summary>
/// <param name="taskName">task name</param>
/// <param name="isEnabled">true - if enabled, false - otherwise</param>
public static void CreateDefaultTask(string taskName, bool isEnabled)
{
try
{
DeleteTask(taskName);
TaskService service = new TaskService();
TaskDefinition td = service.NewTask();
td.Settings.Enabled = isEnabled;
td.RegistrationInfo.Description = "Free Driver Scout";
td.Principal.RunLevel = TaskRunLevel.Highest;
// Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add(new ExecAction(Environment.CurrentDirectory + "\\1Click.exe", null, Environment.CurrentDirectory));
WeeklyTrigger mTrigger = new WeeklyTrigger();
mTrigger.DaysOfWeek = DaysOfTheWeek.Friday;
mTrigger.StartBoundary = DateTime.Today.AddHours(12);
mTrigger.Repetition.StopAtDurationEnd = false;
td.Triggers.Add(mTrigger);
// Register the task in the root folder
service.RootFolder.RegisterTaskDefinition(taskName, td);
}
catch { }
}
示例6: Install
public void Install(IEnumerable<RepetitiveTask> tasks)
{
tasks = tasks.ToList();
using (var ts = new TaskService())
{
var path = Assembly.GetEntryAssembly().Location;
foreach (var t in tasks)
{
var definition = ts.NewTask();
definition.Settings.Enabled = true;
definition.RegistrationInfo.Description = t.Description;
AddTrigger(definition, t);
definition.Actions.Add(new ExecAction(t.Path ?? path, t.Parameters, Path.GetDirectoryName(path)));
ts.RootFolder.RegisterTaskDefinition(
t.Name,
definition,
TaskCreation.CreateOrUpdate,
"SYSTEM",
null,
TaskLogonType.ServiceAccount);
OnTaskInstalledEvent(new TaskEventArgs { Task = t });
}
}
}
示例7: SaveTask
public void SaveTask(string name, string time, string day, string route, int posicion, string accion)
{
using (TaskService ts = new TaskService())
{
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = accion;
WeeklyTrigger week = new WeeklyTrigger();
week.StartBoundary = Convert.ToDateTime(DateTime.Today.ToShortDateString() + " " + time);
week.WeeksInterval = 1;
switch (day)
{
case "Monday":
week.DaysOfWeek = Microsoft.Win32.TaskScheduler.DaysOfTheWeek.Monday;
break;
case "Tuesday":
week.DaysOfWeek = Microsoft.Win32.TaskScheduler.DaysOfTheWeek.Tuesday;
break;
case "Wednesday":
week.DaysOfWeek = Microsoft.Win32.TaskScheduler.DaysOfTheWeek.Wednesday;
break;
case "Thursday":
week.DaysOfWeek = Microsoft.Win32.TaskScheduler.DaysOfTheWeek.Thursday;
break;
case "Friday":
week.DaysOfWeek = Microsoft.Win32.TaskScheduler.DaysOfTheWeek.Friday;
break;
case "Saturday":
week.DaysOfWeek = Microsoft.Win32.TaskScheduler.DaysOfTheWeek.Saturday;
break;
case "Sunday":
week.DaysOfWeek = Microsoft.Win32.TaskScheduler.DaysOfTheWeek.Sunday;
break;
default:
break;
}
td.Triggers.Add(week);
string turn_on;
if (chkTurnOn.Checked)
{
turn_on = " T";
}
else
{
turn_on = " F";
}
if (posicion != -1)
{
td.Actions.Add(new ExecAction(route, posicion.ToString() + turn_on, null));
}
else {
td.Actions.Add(new ExecAction(route, posicion.ToString() + turn_on, null));
}
ts.RootFolder.RegisterTaskDefinition(name, td);
}
}
示例8: Init
public void Init()
{
_taskServiceConvertorFactory = new Mock<ITaskServiceConvertorFactory>();
_nativeService = new TaskService();//localhost
_nativeTask = _nativeService.NewTask();//actually a definition , not an actual task
_nativeInstance = _nativeTask.Actions;
}
示例9: Init
public void Init()
{
_service = new TaskService();
_folder = _service.RootFolder.SubFolders.Any(a => a.Name == "WarewolfTestFolder") ? _service.GetFolder("WarewolfTestFolder") : _service.RootFolder.CreateFolder("WarewolfTestFolder");
var task = _service.NewTask();
task.Actions.Add(new ExecAction("Notepad.exe"));
_folder.RegisterTaskDefinition("TestTask", task);
}
示例10: btnInput_Click
private void btnInput_Click(object sender, EventArgs e)
{
string strTaskID = "";
string appPath = System.Configuration.ConfigurationManager.AppSettings["AutoGetOdds"];
Application.DoEvents();
Cursor.Current = Cursors.WaitCursor;
try
{
// Get the service on the local machine
TaskService ts = new TaskService();
// Delete Schedules
DataTable dt = oddBO.GetSchedules(1);
foreach (DataRow dr in dt.Rows)
{
strTaskID = dr["TaskID"].ToString();
if (ts.FindTask(strTaskID, true) != null)
{
// Remove the task we just created
ts.RootFolder.DeleteTask(strTaskID);
}
// Delete schedules follow taskid
oddBO.DeleleSchedules(strTaskID);
}
DateTime currDate = dtpDate.Value;
// Create Schedules
dt = oddBO.GetSchedules(0, currDate);
foreach (DataRow dr in dt.Rows)
{
strTaskID = dr["TaskID"].ToString();
// Create a new task definition and assign properties
TaskDefinition td = ts.NewTask();
Trigger t = new TimeTrigger();
t.StartBoundary = Convert.ToDateTime(dr["RunTime"].ToString());
td.RegistrationInfo.Description = "Get odd at " + dr["RunTime"].ToString();
// Create a trigger that will fire the task at this time every other day
td.Triggers.Add(t);
// Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add(new ExecAction(appPath, "\"" + strTaskID + "\"", null));
// Register the task in the root folder
ts.RootFolder.RegisterTaskDefinition(strTaskID, td);
}
MessageBox.Show("Schedules have inputed successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
Cursor.Current = Cursors.WaitCursor;
}
}
示例11: Init
public void Init()
{
_taskService = new TaskService();
var newTask = _taskService.NewTask();
var action = new ExecAction("bob.exe");
newTask.Actions.Add(action);
newTask.Triggers.Add(new DailyTrigger());
_taskService.RootFolder.RegisterTaskDefinition("UnitTestTask",newTask);
_factory = new Mock<ITaskServiceConvertorFactory>();
}
示例12: ScheduledTask
public ScheduledTask(string taskName, string taskDescription)
{
this.taskName = taskName;
this.taskDescription = taskDescription;
task = new TaskService();
taskDef = task.NewTask();
this.serialActions = new List<SerialAction>();
this.serialTriggers = new List<SerialTrigger>();
this.triggers = new List<Trigger>();
this.actions = new List<ExecAction>();
}
示例13: EnableStartupTask
public static void EnableStartupTask()
{
using (TaskService _taskService = new TaskService())
{
TaskDefinition _def = _taskService.NewTask();
_def.Triggers.Add(new LogonTrigger() { Enabled = true });
_def.Actions.Add(new ExecAction(Assembly.GetEntryAssembly().Location));
_def.Principal.RunLevel = TaskRunLevel.Highest;
_taskService.RootFolder.RegisterTaskDefinition(_taskName, _def);
}
}
示例14: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
try
{
// Get the service on the local machine
using (var ts = new TaskService())
{
bool isTaskFound = ts.RootFolder.GetTasks().Any(task => task.Name == "BethedaContentSync");
if (!isTaskFound)
{
// Create a new task definition and assign properties
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "Bethesda Employee, Patient and Physician import task.";
// Create a trigger that will fire the task at this time every day
td.Triggers.Add(new DailyTrigger
{
StartBoundary = DateTime.Now.AddHours(-DateTime.Now.Hour),
DaysInterval = 1,
Enabled = true
});
// Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add(new ExecAction(Request.Url.Host, "", null));
// Register the task in the root folder
ts.RootFolder.RegisterTaskDefinition(@"BethedaContentSync", td);
}
}
var formHandlerServiceClient = Utilities.GetConsentFormSvcClient();
formHandlerServiceClient.SynchronizeBethesdaData();
}
catch (Exception ex)
{
try
{
var client = Utilities.GetConsentFormSvcClient();
client.CreateLog(Utilities.GetUsername(Session), LogType.E,
GetType().Name + "-" + new StackTrace().GetFrame(0).GetMethod().ToString(),
ex.Message + Environment.NewLine + ex.StackTrace);
Response.Write(ex.Message);
Response.Write(ex.StackTrace);
}
catch (Exception)
{
}
}
}
示例15: EnableLaunchOnStartup
public static void EnableLaunchOnStartup()
{
using (var taskService = new TaskService())
{
var task = taskService.NewTask();
task.RegistrationInfo.Description = "Starts Overlook Server On Login";
task.Triggers.Add(new LogonTrigger());
task.Actions.Add(new ExecAction(Application.ExecutablePath));
task.Principal.RunLevel = TaskRunLevel.Highest;
taskService.RootFolder.RegisterTaskDefinition(TaskName, task);
ApplicationSettings.LaunchOnLoginTask = TaskName;
}
}