diff --git a/Netch/Controllers/MainController.cs b/Netch/Controllers/MainController.cs index c28969a1cf..305aa42da8 100644 --- a/Netch/Controllers/MainController.cs +++ b/Netch/Controllers/MainController.cs @@ -193,7 +193,17 @@ public static void TryReleaseTcpPort(ushort port, string portName) { foreach (var p in PortHelper.GetProcessByUsedTcpPort(port)) { - if (p.MainModule!.FileName.StartsWith(Global.NetchDir)) + try + { + _ = p.MainModule!.FileName; + } + catch (Exception e) + { + Logging.Warning(e.ToString()); + continue; + } + + if (p.MainModule.FileName.StartsWith(Global.NetchDir)) { p.Kill(); p.WaitForExit(); diff --git a/Netch/Utils/PortHelper.cs b/Netch/Utils/PortHelper.cs index 459ecd881d..27df68cc15 100644 --- a/Netch/Utils/PortHelper.cs +++ b/Netch/Utils/PortHelper.cs @@ -33,7 +33,7 @@ public static IEnumerable GetProcessByUsedTcpPort(ushort port) if (port == 0) throw new ArgumentOutOfRangeException(); - var row = GetTcpTable2().Where(r => ntohs((ushort) r.dwLocalPort) == port); + var row = GetTcpTable2().Where(r => ntohs((ushort) r.dwLocalPort) == port).Where(r => r.dwOwningPid is not (0 or 4)); return row.Select(r => Process.GetProcessById((int) r.dwOwningPid)); }