【修改】 启动本地判分程序前,先检测是否已经启动,启动则不启动

This commit is contained in:
MSI\letre
2025-07-10 16:34:35 +08:00
parent cc7ebe55d9
commit 885f70fb56

View File

@@ -1,17 +1,18 @@
using Applications;
using Microsoft.Win32;
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Net;
using System.Security.Cryptography;
using System.Text.Json;
using System.Xml.Linq;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using MySql.Data.MySqlClient;
using System.Net;
using System.Net.NetworkInformation;
using System.Security.Cryptography;
using System.Security.Principal;
using System.ServiceProcess;
using System.Text.Json;
using System.Xml.Linq;
using Applications;
using Microsoft.Win32;
using MySql.Data.MySqlClient;
class Program
{
@@ -70,8 +71,13 @@ class Program
WorkingDirectory = workingDirectory, // 必须!
UseShellExecute = true // 或 false根据需要
};
// 检测一下端口是否被占用48080
if (!IsPortInUse(48082))
{
Process.Start(startInfo);
}
}
}
else if (action == "/start")
{
@@ -510,6 +516,21 @@ class Program
list.Add(sql.Substring(start));
return list;
}
public static bool IsPortInUse(int port)
{
IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
TcpConnectionInformation[] tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections();
foreach (TcpConnectionInformation tcpi in tcpConnInfoArray)
{
if (tcpi.LocalEndPoint.Port == port)
{
return true; // 端口被占用
}
}
return false; // 端口可用
}
// 获取当前登录用户 SID
static string GetCurrentUserSid()