Update GetProcessByUsedTcpPort (Fix #591)

This commit is contained in:
ChsBuffer
2021-03-23 16:14:34 +08:00
parent 8e545fc05f
commit 8269948288
2 changed files with 12 additions and 2 deletions

View File

@@ -193,7 +193,17 @@ namespace Netch.Controllers
{
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();

View File

@@ -33,7 +33,7 @@ namespace Netch.Utils
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));
}