diff --git a/FastGithub.DomainResolve/DnscryptProxy.cs b/FastGithub.DomainResolve/DnscryptProxy.cs index 4a105da..55c4870 100644 --- a/FastGithub.DomainResolve/DnscryptProxy.cs +++ b/FastGithub.DomainResolve/DnscryptProxy.cs @@ -80,7 +80,7 @@ namespace FastGithub.DomainResolve process.WaitForExit(); } - if (OperatingSystem.IsWindows()) + if (OperatingSystem.IsWindows() && Process.GetCurrentProcess().SessionId == 0) { StartDnscryptProxy("-service uninstall")?.WaitForExit(); StartDnscryptProxy("-service install")?.WaitForExit(); @@ -96,7 +96,7 @@ namespace FastGithub.DomainResolve { this.LocalEndPoint = localEndPoint; this.process.EnableRaisingEvents = true; - this.process.Exited += Process_Exited; + this.process.Exited += (s, e) => this.LocalEndPoint = null; } } @@ -107,7 +107,7 @@ namespace FastGithub.DomainResolve { try { - if (OperatingSystem.IsWindows()) + if (OperatingSystem.IsWindows() && Process.GetCurrentProcess().SessionId == 0) { StartDnscryptProxy("-service stop")?.WaitForExit(); StartDnscryptProxy("-service uninstall")?.WaitForExit(); @@ -158,16 +158,6 @@ namespace FastGithub.DomainResolve throw new FastGithubException("当前无可用的端口"); } - /// - /// 进程退出时 - /// - /// - /// - private void Process_Exited(object? sender, EventArgs e) - { - this.LocalEndPoint = null; - } - /// /// 启动DnscryptProxy进程 ///