-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.cs
37 lines (26 loc) · 1.11 KB
/
Utils.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
using System.Net;
namespace TencentCloudVPCTemplateUpdater;
public static class Utils {
public const string ServiceName = "LC6464 TencentCloud VPC Template Updater";
public static readonly TimeSpan TimeSpan1s = TimeSpan.FromSeconds(1);
public static readonly HttpClient httpClient = new() {
BaseAddress = new("https://api.lcwebsite.cn/GetIP"),
Timeout = TimeSpan.FromSeconds(5),
DefaultRequestVersion = HttpVersion.Version30,
DefaultVersionPolicy = HttpVersionPolicy.RequestVersionExact
};
public static async Task Delay1sAsync() => await Task.Delay(TimeSpan1s).ConfigureAwait(false);
public static void ExecuteScQuery() => ExecuteScAction("query");
public static void ExecuteScAction(string action) => ExecuteScCommand($"{action} \"{ServiceName}\"");
public static void ExecuteScCommand(string arguments) {
using var process = Process.Start(new ProcessStartInfo {
FileName = "sc.exe",
Arguments = arguments,
CreateNoWindow = true,
RedirectStandardError = true,
RedirectStandardOutput = true,
});
process?.WaitForExit();
Console.WriteLine(process?.StandardOutput.ReadToEnd());
}
}