本文整理汇总了C#中Microsoft.Win32.TaskScheduler.TaskService.GetFolder方法的典型用法代码示例。如果您正苦于以下问题:C# TaskService.GetFolder方法的具体用法?C# TaskService.GetFolder怎么用?C# TaskService.GetFolder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Win32.TaskScheduler.TaskService
的用法示例。
在下文中一共展示了TaskService.GetFolder方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: PersistTask
public static bool PersistTask(bool startAtLogon, bool startForAllUsers)
{
WinTasks.TaskService ts = new WinTasks.TaskService();
try
{
WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent();
bool isElevated = (new WindowsPrincipal(currentIdentity).IsInRole(WindowsBuiltInRole.Administrator));
WinTasks.Task task = ts.FindTask(Application.ProductName, false);
if (startAtLogon)
{
if (startForAllUsers && !isElevated)
{
return PersistTaskElevated(startAtLogon, startForAllUsers);
}
else
{
WinTasks.LogonTrigger trigger = (WinTasks.LogonTrigger)WinTasks.LogonTrigger.CreateTrigger(WinTasks.TaskTriggerType.Logon);
trigger.Enabled = true;
trigger.StartBoundary = DateTime.Today;
if (startForAllUsers)
trigger.UserId = null;
else
trigger.UserId = currentIdentity.Name;
WinTasks.ExecAction action = (WinTasks.ExecAction)WinTasks.ExecAction.CreateAction(WinTasks.TaskActionType.Execute);
action.Path = Application.ExecutablePath;
action.WorkingDirectory = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
if (task == null)
{
task = ts.AddTask(Application.ProductName, trigger, action, currentIdentity.Name);
}
else
{
task.Definition.Triggers.Clear();
task.Definition.Triggers.Add(trigger);
task.Definition.Actions.Clear();
task.Definition.Actions.Add(action);
task.RegisterChanges();
}
}
}
else if (task != null)
{
ts.GetFolder("\\").DeleteTask(task.Name);
}
}
catch
{
return false;
}
finally
{
ts.Dispose();
}
return true;
}
示例3: loadTaskFolder
private static TaskFolder loadTaskFolder() {
TaskService ts = new TaskService();
TaskFolder folder;
try {
folder = ts.GetFolder(@"\"+Constants.TASK_SCHEDULER_FOLDER);
}
catch (FileNotFoundException) {
folder = ts.RootFolder.CreateFolder(@"\"+Constants.TASK_SCHEDULER_FOLDER);
}
return folder;
}
示例4: CleanTasks
public static ActionResult CleanTasks(Session session)
{
try
{
var taskService = new TaskService();
var existingTasks = taskService.GetFolder("FOG").AllTasks.ToList();
foreach (var task in existingTasks)
taskService.RootFolder.DeleteTask(@"FOG\" + task.Name);
taskService.RootFolder.DeleteFolder("FOG", false);
}
catch (Exception ) { }
return ActionResult.Success;
}
示例5: CleanTasks
public static ActionResult CleanTasks(Session session)
{
try
{
var config = GetSettings();
if (GetValue("LIGHT", config).Equals("1"))
return ActionResult.Success;
var taskService = new TaskService();
var existingTasks = taskService.GetFolder("FOG").AllTasks.ToList();
foreach (var task in existingTasks)
taskService.RootFolder.DeleteTask(@"FOG\" + task.Name);
taskService.RootFolder.DeleteFolder("FOG", false);
taskService.Dispose();
}
catch (Exception)
{
// ignored
}
return ActionResult.Success;
}
示例6: FilterTasks
private List<string> FilterTasks(List<string> newTasks)
{
var taskService = new TaskService();
try
{
taskService.RootFolder.CreateFolder("FOG");
}
catch (Exception)
{
}
var existingTasks = taskService.GetFolder("FOG").AllTasks.ToList();
foreach (var task in existingTasks)
if (!newTasks.Contains(task.Name))
{
Log.Entry(Name, "Delete task " + task.Name);
taskService.RootFolder.DeleteTask(@"FOG\" + task.Name);
//If the existing task is not in the new list delete it
}
else
{
Log.Entry(Name, task.Name + " already scheduled");
newTasks.Remove(task.Name); //Remove the existing task from the queue
}
return newTasks;
}
示例7: GetTaskFolder
private TaskFolder GetTaskFolder(TaskService ts, string folderName)
{
TaskFolder sysconTaskFolder = null;
try
{
sysconTaskFolder = ts.GetFolder("Syscon");
}
catch (Exception ex)
{
Env.Log("Could not find the Syscon task scheduler folder. Trying to create one.");
}
return sysconTaskFolder;
}
示例8: WhenTheIsExecutedTimes
public void WhenTheIsExecutedTimes(string scheduleName, int times)
{
try
{
int i = 0;
var x = new TaskService();
x.GetFolder("Warewolf");
var task = x.FindTask(scheduleName);
do
{
task.Run();
const int TimeOut = 10;
int time = 0;
while(task.State == TaskState.Running && time < TimeOut)
{
time++;
Thread.Sleep(1000);
}
i++;
} while(i < times);
}
catch(Exception e)
{
ScenarioContext.Current["Error"] = e;
}
}
示例9: WizardTest
internal static void WizardTest(TaskService ts, System.IO.TextWriter output, params string[] arg)
{
try
{
string FolderName = "My Folder";
bool v2 = ts.HighestSupportedVersion > new Version(1, 1);
var taskFolder = ts.RootFolder;
if (v2)
{
try
{
taskFolder = ts.GetFolder(FolderName);
}
catch (System.IO.FileNotFoundException)
{
taskFolder = ts.RootFolder.CreateFolder(FolderName);
}
}
using (var taskSchedulerWizard = new TaskSchedulerWizard())
{
var newTaskDefinition = ts.NewTask();
newTaskDefinition.Actions.Add(new ExecAction("notepad.exe"));
taskSchedulerWizard.Initialize(ts, newTaskDefinition);
taskSchedulerWizard.TaskFolder = FolderName;
taskSchedulerWizard.RegisterTaskOnFinish = true;
taskSchedulerWizard.AvailableTriggers = TaskSchedulerWizard.AvailableWizardTriggers.Event;
taskSchedulerWizard.AvailablePages = TaskSchedulerWizard.AvailableWizardPages.IntroPage |
//TaskSchedulerWizard.AvailableWizardPages.TriggerSelectPage |
TaskSchedulerWizard.AvailableWizardPages.TriggerEditPage |
//TaskSchedulerWizard.AvailableWizardPages.TriggerPropertiesPage |
TaskSchedulerWizard.AvailableWizardPages.ActionEditPage |
//TaskSchedulerWizard.AvailableWizardPages.SecurityPage |
TaskSchedulerWizard.AvailableWizardPages.SummaryPage;
if (taskSchedulerWizard.ShowDialog() == DialogResult.OK)
taskFolder.DeleteTask(taskSchedulerWizard.Task.Name);
// _tlv.Tasks = taskFolder.Tasks;
}
// Create a new task definition and assign properties
/*TaskSchedulerWizard wiz = new TaskSchedulerWizard(ts, null, true) { TaskFolder = @"\Microsoft" };
if (wiz.ShowDialog() == DialogResult.OK)
{
Task t = wiz.Task;
if (t.Definition.Triggers.Count > 1)
new TaskEditDialog(t).ShowDialog();
else
{
wiz.AvailablePages = TaskSchedulerWizard.AvailableWizardPages.TriggerPropertiesPage | TaskSchedulerWizard.AvailableWizardPages.TriggerSelectPage | TaskSchedulerWizard.AvailableWizardPages.SummaryPage;
wiz.AvailableTriggers = TaskSchedulerWizard.AvailableWizardTriggers.Daily | TaskSchedulerWizard.AvailableWizardTriggers.Time | TaskSchedulerWizard.AvailableWizardTriggers.Weekly | TaskSchedulerWizard.AvailableWizardTriggers.Monthly | TaskSchedulerWizard.AvailableWizardTriggers.MonthlyDOW;
wiz.AllowEditorOnFinish = true;
wiz.EditorOnFinishText = "Show dialog";
wiz.TriggerPagePrompt = "When???";
wiz.RegisterTaskOnFinish = true;
wiz.SummaryRegistrationNotice = "Done when you click Finish";
wiz.SummaryFormatString = "Name: {0}\r\nDescription: {1}\r\nTrigger: {2}";
wiz.Title = "My Wizard";
wiz.Initialize(t);
wiz.ShowDialog();
}
}
if (wiz.Task != null)
ts.RootFolder.DeleteTask(wiz.Task.Path);*/
}
catch (Exception ex)
{
output.WriteLine(ex.ToString());
}
}
示例10: disableRunningZombieTasks
static void disableRunningZombieTasks()
{
using (TaskService ts = new TaskService())
{
if (!ts.Connected)
{
RunningTaskCollection runningTasks = ts.GetRunningTasks();
TaskFolder KNXFolder = ts.GetFolder("KNX");
for (var i = 0; i < runningTasks.Count; i++)
{
if (runningTasks[i].Folder.Path == "\\KNX")
{
if (runningTasks[i].NextRunTime < DateTime.Now)
{
runningTasks[i].Enabled = false;
runningTasks[i].Stop();
}
}
}
}
}
}
示例11: ClearAll
public void ClearAll()
{
var taskService = new TaskService();
try
{
taskService.RootFolder.CreateFolder("FOG");
}
catch (Exception)
{
// ignored
}
var existingTasks = taskService.GetFolder("FOG").AllTasks.ToList();
foreach (var task in existingTasks)
{
Log.Debug(LogName, "Delete task " + task.Name);
taskService.RootFolder.DeleteTask(@"FOG\" + task.Name);
}
taskService.Dispose();
}