-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTaskSchedulerOperations.cs
More file actions
48 lines (40 loc) · 1.67 KB
/
TaskSchedulerOperations.cs
File metadata and controls
48 lines (40 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using Microsoft.Win32.TaskScheduler;
namespace TrexMinerGUI
{
public static class TaskSchedulerOperations
{
public static string TaskName = "TrexMinerGUI";
public static void AddToTS()
{
using (TaskService ts = new TaskService())
{
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = @"Opens TrexMinerGUI";
//td.Principal.LogonType = TaskLogonType.InteractiveToken;
td.Principal.RunLevel = TaskRunLevel.Highest;
td.Settings.StopIfGoingOnBatteries = false;
td.Settings.DisallowStartIfOnBatteries = false;
//td.Triggers.Add(new LogonTrigger { UserId = System.Security.Principal.WindowsIdentity.GetCurrent().Name });
td.Triggers.Add(new LogonTrigger());
td.Actions.Add(new ExecAction(System.Reflection.Assembly.GetExecutingAssembly().Location.Remove(System.Reflection.Assembly.GetExecutingAssembly().Location.Length - 4) + ".exe", "startup"));
ts.RootFolder.RegisterTaskDefinition(TaskName, td);
}
}
public static void RemoveFromTS()
{
using (TaskService ts = new TaskService())
{
ts.RootFolder.DeleteTask(TaskName);
}
}
public static bool IsItInTS()
{
// THIS CAUSES A DELAY, FIND A BETTER SOLUTION!
using (TaskService ts = new TaskService())
foreach (var TheTask in ts.RootFolder.AllTasks)
if (TheTask.Name == TaskName)
return true;
return false;
}
}
}