From 17bd4f1e206607663284a6d246a5d893eebfda59 Mon Sep 17 00:00:00 2001 From: Vita Chumakova Date: Sat, 16 Nov 2024 04:50:33 +0400 Subject: [PATCH] fix: don't use Powershell for killing smartdnsblock processes (#2258) --- .../OutlineService/OutlineService.cs | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/client/electron/windows/OutlineService/OutlineService/OutlineService.cs b/client/electron/windows/OutlineService/OutlineService/OutlineService.cs index 654dfeec0f..6100fc793e 100755 --- a/client/electron/windows/OutlineService/OutlineService/OutlineService.cs +++ b/client/electron/windows/OutlineService/OutlineService/OutlineService.cs @@ -487,7 +487,7 @@ public void ResetRouting(string proxyIp, int gatewayInterfaceIndex) try { - // This is only necessary when disconecting without network connectivity. + // This is only necessary when disconecting without network connectivity. StartRoutingIpv4(); } catch (Exception) {} @@ -531,7 +531,7 @@ public void ResetRouting(string proxyIp, int gatewayInterfaceIndex) { StopSmartDnsBlock(); eventLog.WriteEntry($"stopped smartdnsblock"); - } + } catch (Exception e) { eventLog.WriteEntry($"failed to stop smartdnsblock: {e.Message}", @@ -606,15 +606,24 @@ private void StartSmartDnsBlock() } } - private void StopSmartDnsBlock() + private static void StopSmartDnsBlock() { - try + var errors = new List(0); + foreach (var process in Process.GetProcessesByName("smartdnsblock")) { - RunCommand("powershell", "stop-process -name smartdnsblock"); + try + { + process.Kill(); + } + catch (Exception e) + { + errors.Add(e.Message); + } } - catch (Exception e) + + if (errors.Count > 0) { - throw new Exception($"could not stop smartdnsblock: {e.Message}"); + throw new Exception($"could not stop smartdnsblock: {string.Join("; ", errors)}"); } } @@ -693,7 +702,7 @@ private void StopRoutingIpv4() { RunCommand(CMD_NETSH, $"interface ipv4 set route {subnet} interface={NetworkInterface.LoopbackInterfaceIndex} metric=0 store=active"); } - } + } } private void StartRoutingIpv6() @@ -938,7 +947,7 @@ private void NetworkAddressChanged(object sender, EventArgs evt) // Only send on actual change, to prevent duplicate notifications (mostly // harmless but can make debugging harder). eventLog.WriteEntry($"network changed but gateway and interface stayed the same"); - return; + return; } else if (gatewayIp == null) {