-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
51 lines (39 loc) · 1.25 KB
/
Program.cs
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
49
50
51
if (OperatingSystem.IsWindows()) {
if (args is ["install"]) {
Utils.ExecuteScCommand($"create \"{Utils.ServiceName}\" binpath=\"{Process.GetCurrentProcess().MainModule?.FileName}\" start=\"delayed-auto\" DisplayName=\"LC6464 腾讯云私有网络安全组参数模板 IP 地址更新器\"");
Utils.ExecuteScAction("start");
await Utils.Delay1sAsync().ConfigureAwait(false);
Utils.ExecuteScQuery();
return;
}
if (args is ["uninstall"]) {
Utils.ExecuteScAction("stop");
await Utils.Delay1sAsync().ConfigureAwait(false);
Utils.ExecuteScAction("delete");
return;
}
if (args is ["start"] or ["stop"]) {
Utils.ExecuteScAction(args[0]);
await Utils.Delay1sAsync().ConfigureAwait(false);
Utils.ExecuteScQuery();
return;
}
if (args is ["restart"]) {
Utils.ExecuteScAction("stop");
await Utils.Delay1sAsync().ConfigureAwait(false);
Utils.ExecuteScAction("start");
await Utils.Delay1sAsync().ConfigureAwait(false);
Utils.ExecuteScQuery();
return;
}
if (args is ["status"]) {
Utils.ExecuteScQuery();
return;
}
}
var builder = Host.CreateApplicationBuilder(args);
builder.Services
.AddWindowsService(options => options.ServiceName = Utils.ServiceName)
.AddHostedService<WindowsBackgroundService>();
builder.Build().Run();
return;