mirror of
https://github.com/netchx/netch.git
synced 2026-05-07 22:44:03 +08:00
Replace TaskScheduler COMReference with PackageReference
This commit is contained in:
@@ -37,15 +37,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<COMReference Include="TaskScheduler.dll">
|
||||
<Guid>e34cb9f1-c7f7-424c-be29-027dcc09363a</Guid>
|
||||
<VersionMajor>1</VersionMajor>
|
||||
<VersionMinor>0</VersionMinor>
|
||||
<WrapperTool>tlbimp</WrapperTool>
|
||||
<Lcid>0</Lcid>
|
||||
<Isolated>false</Isolated>
|
||||
<EmbedInteropTypes>false</EmbedInteropTypes>
|
||||
</COMReference>
|
||||
<COMReference Include="NetFwTypeLib.dll">
|
||||
<Guid>58fbcf7c-e7a9-467c-80b3-fc65e8fcca08</Guid>
|
||||
<VersionMajor>1</VersionMajor>
|
||||
@@ -71,6 +62,7 @@
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="System.Collections.Immutable" Version="5.0.0" />
|
||||
<PackageReference Include="System.Reflection.Metadata" Version="5.0.0" />
|
||||
<PackageReference Include="TaskScheduler" Version="2.9.1" />
|
||||
<PackageReference Include="WindowsAPICodePack-Shell" Version="1.1.1" />
|
||||
<PackageReference Include="WindowsJobAPI" Version="5.0.1" />
|
||||
<PackageReference Include="WindowsProxy" Version="5.0.0" />
|
||||
|
||||
@@ -12,7 +12,8 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using MaxMind.GeoIP2;
|
||||
using TaskScheduler;
|
||||
using Microsoft.Win32.TaskScheduler;
|
||||
using Task = System.Threading.Tasks.Task;
|
||||
|
||||
namespace Netch.Utils
|
||||
{
|
||||
@@ -240,47 +241,35 @@ namespace Netch.Utils
|
||||
|
||||
public static void RegisterNetchStartupItem()
|
||||
{
|
||||
var scheduler = new TaskSchedulerClass();
|
||||
scheduler.Connect();
|
||||
var folder = scheduler.GetFolder("\\");
|
||||
|
||||
var taskIsExists = false;
|
||||
try
|
||||
{
|
||||
folder.GetTask("Netch Startup");
|
||||
taskIsExists = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
const string TaskName = "Netch Startup";
|
||||
var folder = TaskService.Instance.GetFolder("\\");
|
||||
var taskIsExists = folder.Tasks.Any(task => task.Name == TaskName);
|
||||
|
||||
if (Global.Settings.RunAtStartup)
|
||||
{
|
||||
if (taskIsExists)
|
||||
folder.DeleteTask("Netch Startup", 0);
|
||||
folder.DeleteTask(TaskName, false);
|
||||
|
||||
var task = scheduler.NewTask(0);
|
||||
task.RegistrationInfo.Author = "Netch";
|
||||
task.RegistrationInfo.Description = "Netch run at startup.";
|
||||
task.Principal.RunLevel = _TASK_RUNLEVEL.TASK_RUNLEVEL_HIGHEST;
|
||||
var td = TaskService.Instance.NewTask();
|
||||
|
||||
task.Triggers.Create(_TASK_TRIGGER_TYPE2.TASK_TRIGGER_LOGON);
|
||||
var action = (IExecAction) task.Actions.Create(_TASK_ACTION_TYPE.TASK_ACTION_EXEC);
|
||||
action.Path = Application.ExecutablePath;
|
||||
td.RegistrationInfo.Author = "Netch";
|
||||
td.RegistrationInfo.Description = "Netch run at startup.";
|
||||
td.Principal.RunLevel = TaskRunLevel.Highest;
|
||||
|
||||
td.Triggers.Add(new LogonTrigger());
|
||||
td.Actions.Add(new ExecAction(Application.ExecutablePath));
|
||||
|
||||
task.Settings.ExecutionTimeLimit = "PT0S";
|
||||
task.Settings.DisallowStartIfOnBatteries = false;
|
||||
task.Settings.RunOnlyIfIdle = false;
|
||||
td.Settings.ExecutionTimeLimit = TimeSpan.Zero;
|
||||
td.Settings.DisallowStartIfOnBatteries = false;
|
||||
td.Settings.RunOnlyIfIdle = false;
|
||||
td.Settings.Compatibility = TaskCompatibility.V2_1;
|
||||
|
||||
folder.RegisterTaskDefinition("Netch Startup", task, (int) _TASK_CREATION.TASK_CREATE, null, null,
|
||||
_TASK_LOGON_TYPE.TASK_LOGON_INTERACTIVE_TOKEN, "");
|
||||
TaskService.Instance.RootFolder.RegisterTaskDefinition("Netch Startup", td);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (taskIsExists)
|
||||
folder.DeleteTask("Netch Startup", 0);
|
||||
folder.DeleteTask(TaskName, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user