本文整理汇总了C#中Microsoft.Win32.TaskScheduler.TaskService.GetTask方法的典型用法代码示例。如果您正苦于以下问题:C# TaskService.GetTask方法的具体用法?C# TaskService.GetTask怎么用?C# TaskService.GetTask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Win32.TaskScheduler.TaskService
的用法示例。
在下文中一共展示了TaskService.GetTask方法的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: IsAutostart
public static bool IsAutostart()
{
using (TaskService ts = new TaskService())
{
Microsoft.Win32.TaskScheduler.Task task = ts.GetTask("Touchmote");
return task != null;
}
}
示例3: DeleteTask
public void DeleteTask(string name)
{
using (TaskService ts = new TaskService())
{
if (ts.GetTask(name) != null)
{
ts.RootFolder.DeleteTask(name);
}
}
}
示例4: modifyTask
public static void modifyTask(DailyTrigger dt)
{
using (TaskService ts = new TaskService())
{
Task t = ts.GetTask("taxiService");
TaskDefinition td = t.Definition;
td.Triggers.Add(dt);
ts.RootFolder.RegisterTaskDefinition(@"taxiService", td);
}
}
示例5: RunTask
public static void RunTask()
{
using (TaskService ts = new TaskService())
{
Task t = ts.GetTask("CudaAdministratorSkipUAC");
if (t != null)
{
t.Run();
}
}
}
示例6: JobScheduler
/// <summary>
/// Ctor
/// </summary>
public JobScheduler()
{
InitializeComponent();
LoadJobPlugIns();
try
{
using (TaskService ts = new TaskService())
{
//Load which jobs are already scheduled in the service.
foreach (IScheduledJob job in this.ScheduledJobs)
{
job.JobConfig.LoadConfig();
string jobName = job.ToString().Substring(job.ToString().LastIndexOf('.') + 1);
string taskName = jobName + "-" + job.JobId.ToString();
TaskFolder sysconTaskFolder = GetTaskFolder(ts, SYSCON_TASK_FOLDER);
Task t = null;
// Retrieve the task
if (sysconTaskFolder != null)
{
//Get from Syscon folder
t = sysconTaskFolder.Tasks.FirstOrDefault(tt => tt.Name == taskName);
}
else
{
//get from Root folder
t = ts.GetTask(taskName);
}
job.JobConfig.ScheduledTime = (t != null) ? t.Definition.Triggers[0].ToString() : NOT_SET;
job.JobStatus = (t != null) ? (JobStatus)t.State : JobStatus.Disabled;
job.Enqueued = (t != null);
job.JobConfig.SaveConfig();
}
}
}
catch (Exception ex)
{
Env.Log("Exception in accessing the windows task scheduler information for the plug-ins.\nException: {0}\n StackTrace: {1}", ex.Message, ex.StackTrace);
if (ex.InnerException != null)
{
Env.Log("InnerException: {0}\n StackTrace: {1}", ex.InnerException.Message, ex.InnerException.StackTrace);
}
}
}
示例7: Delete
public void Delete(IEnumerable<RepetitiveTask> tasks)
{
using (var ts = new TaskService())
{
foreach (var t in tasks)
{
var task = ts.GetTask(t.Name);
if (task != null)
{
WaitForTaskToComplete(task, t);
ts.RootFolder.DeleteTask(t.Name);
OnTaskDeletedEvent(new TaskEventArgs { Task = t });
}
}
}
}
示例8: Disable
public void Disable(IEnumerable<RepetitiveTask> tasks)
{
using (var ts = new TaskService())
{
foreach (var t in tasks)
{
var task = ts.GetTask(t.Name);
if (task != null)
{
WaitForTaskToComplete(task, t);
task.Enabled = false;
task.RegisterChanges();
OnTaskDisabledEvent(new TaskEventArgs { Task = t });
}
}
}
}
示例9: Main
static void Main(string[] args) {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
for (int x = 0, cx = args.Length; x < cx; x++) {
if ("/tn".Equals(args[x], StringComparison.InvariantCultureIgnoreCase)) {
x++;
if (x < cx) {
using (TaskService ts = new TaskService()) {
var t = ts.GetTask(args[x]);
if (t.ShowEditor()) {
t.RegisterChanges();
}
}
break;
}
}
}
}
示例10: 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());
}
}
示例11: jobsDataGridView_CellClick
private void jobsDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex < 0)
return;
ScheduledJobModel scheduledJobModel = (ScheduledJobModel)jobsDataGridView.Rows[e.RowIndex].DataBoundItem;
if (e.ColumnIndex == jobsDataGridView.Columns["Config"].Index && e.RowIndex >= 0)
{
scheduledJobModel.Job.SetJobConfiguration();
}
if (e.ColumnIndex == jobsDataGridView.Columns["Enqueue"].Index && e.RowIndex >= 0)
{
DataGridViewCheckBoxColumn col = jobsDataGridView.Columns["Enqueue"] as DataGridViewCheckBoxColumn;
DataGridViewCheckBoxCell cell = jobsDataGridView.Rows[e.RowIndex].Cells["Enqueue"] as DataGridViewCheckBoxCell;
bool enqueued = !((bool)cell.EditingCellFormattedValue);
//Add the entry to service app.config file.
string exeLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
//Add to the windows scheduler
using (TaskService ts = new TaskService())
{
string jobName = scheduledJobModel.Job.ToString().Substring(scheduledJobModel.Job.ToString().LastIndexOf('.') + 1);
string taskName = jobName + "-" + scheduledJobModel.Job.JobId.ToString();
if (enqueued)
{
//If enqueued then add to the scheduled task list
ScheduledTaskSettingsDialog schedulerTaskSettingsDlg = new ScheduledTaskSettingsDialog();
if (schedulerTaskSettingsDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
// Create a new task definition and assign properties
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = scheduledJobModel.Job.JobDesc;
td.Principal.LogonType = TaskLogonType.InteractiveToken;
td.Principal.RunLevel = TaskRunLevel.Highest;
td.Settings.DisallowStartIfOnBatteries = false;
td.Settings.StopIfGoingOnBatteries = false;
// Add a trigger that will fire the task at this time every day
DailyTrigger dt = (DailyTrigger)td.Triggers.Add(new DailyTrigger { DaysInterval = 1, StartBoundary = schedulerTaskSettingsDlg.StartBoundary });
dt.Repetition.Interval = TimeSpan.FromMinutes(schedulerTaskSettingsDlg.TimeInterval);
// Add an action that will launch the job runner application for the given job at the scheduled time.
td.Actions.Add(new ExecAction("ScheduledJobRunner.exe", scheduledJobModel.Job.JobId.ToString(), exeLocation));
//Try creating the Syscon folder
TaskFolder sysconTaskFolder = CreateSysconScheduledTaskFolder(ts);
if (sysconTaskFolder != null)
{
// Register the task in the Syscon folder
sysconTaskFolder.RegisterTaskDefinition(taskName, td);
}
else
{
// Register the task in the root folder
ts.RootFolder.RegisterTaskDefinition(taskName, td);
}
scheduledJobModel.Enqueued = enqueued;
//cell.EditingCellFormattedValue = true;
scheduledJobModel.ScheduledTime = td.Triggers[0].ToString();
scheduledJobModel.JobStatus = JobStatus.Ready;
scheduledJobModel.Job.JobConfig.ScheduledTime = scheduledJobModel.ScheduledTime;
scheduledJobModel.Job.JobConfig.SaveConfig();
MessageBox.Show("Job successfully added to the Windows scheduled tasks.");
}
else
{
scheduledJobModel.Enqueued = false;
//cell.EditingCellFormattedValue = false;
}
}
else
{
Task t = null;
TaskFolder sysconTaskFolder = GetTaskFolder(ts, SYSCON_TASK_FOLDER);
if (sysconTaskFolder != null)
{
//Get from Syscon folder
t = sysconTaskFolder.Tasks.FirstOrDefault(tt => tt.Name == taskName);
//Remove the task from Syscon folder
sysconTaskFolder.DeleteTask(taskName, false);
}
else
{
t = ts.GetTask(taskName);
//Remove the task from Root folder
ts.RootFolder.DeleteTask(taskName, false);
}
scheduledJobModel.Enqueued = false;
scheduledJobModel.ScheduledTime = NOT_SET;
scheduledJobModel.JobStatus = JobStatus.Disabled;
//.........这里部分代码省略.........
示例12: GetScheduledTask
public Microsoft.Win32.TaskScheduler.Task GetScheduledTask()
{
using (TaskService ts = new TaskService())
{
Microsoft.Win32.TaskScheduler.Task t = ts.GetTask(m_internalTaskName);
return t;
}
}
示例13: Clean
public void Clean()
{
if (m_task == null) return;
using (TaskService ts = new TaskService())
{
Microsoft.Win32.TaskScheduler.Task t = ts.GetTask(m_internalTaskName);
if (t != null) ts.RootFolder.DeleteTask(m_internalTaskName);
}
}
示例14: Persist
/// <summary>
/// Saves the specified sections of the security descriptor associated with this <see cref="T:System.Security.AccessControl.ObjectSecurity" /> object to permanent storage. We recommend that the values of the <paramref name="includeSections" /> parameters passed to the constructor and persist methods be identical. For more information, see Remarks.
/// </summary>
/// <param name="name">The name used to retrieve the persisted information.</param>
/// <param name="includeSections">One of the <see cref="T:System.Security.AccessControl.AccessControlSections" /> enumeration values that specifies the sections of the security descriptor (access rules, audit rules, owner, primary group) of the securable object to save.</param>
protected override void Persist(string name, AccessControlSections includeSections = AccessControlSections.Access | AccessControlSections.Group | AccessControlSections.Owner)
{
using (var ts = new TaskService())
{
var task = ts.GetTask(name);
Persist(task, includeSections);
}
}
示例15: StartNew
private void StartNew(DateTime startTime, string action, string parameters, string taskName)
{
using (TaskService ts = new TaskService())
{
TaskDefinition td = ts.NewTask();
td.Principal.RunLevel = TaskRunLevel.Highest;
td.RegistrationInfo.Description = "instaprinter";
td.Triggers.Add(new TimeTrigger(startTime));
td.Actions.Add(new ExecAction(action, parameters));
// Retrieve the task, change the trigger and re-register it
Task t = ts.GetTask(taskName);
if (t != null)
{
td = t.Definition;
td.Triggers[0].StartBoundary = startTime;
ts.RootFolder.RegisterTaskDefinition(taskName, td);
}
else
{
ts.RootFolder.RegisterTaskDefinition(taskName, td);
}
}
}