|
@@ -9,6 +9,9 @@ using System.Windows.Forms;
|
|
|
using Microsoft.Win32;
|
|
|
using System.Diagnostics;
|
|
|
using System.IO;
|
|
|
+using System.Net.NetworkInformation;
|
|
|
+using System.Net;
|
|
|
+using System.Threading;
|
|
|
|
|
|
namespace WinBox
|
|
|
{
|
|
@@ -66,9 +69,11 @@ namespace WinBox
|
|
|
process.StartInfo.RedirectStandardOutput = true;
|
|
|
process.Start();
|
|
|
StreamReader reader = process.StandardOutput;
|
|
|
+
|
|
|
while (!reader.EndOfStream)
|
|
|
{
|
|
|
string msg = reader.ReadLine().ToUpper();
|
|
|
+ MessageBox.Show(msg);
|
|
|
if (msg.IndexOf("TCP") > 0 && msg.IndexOf(":" + tcpPort) > 0)
|
|
|
{
|
|
|
string info = msg.Trim();
|
|
@@ -90,7 +95,6 @@ namespace WinBox
|
|
|
{
|
|
|
MessageBox.Show("检测TCP端口:" + tcpPort + "失败!" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
private void Form1_Activated(object sender, System.EventArgs e)
|
|
@@ -110,6 +114,7 @@ namespace WinBox
|
|
|
pro.Start();
|
|
|
pro.Close();
|
|
|
|
|
|
+ // detectionPort();
|
|
|
}
|
|
|
|
|
|
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
|
|
@@ -199,7 +204,31 @@ namespace WinBox
|
|
|
private void MainForm_Shown(object sender, EventArgs e)
|
|
|
{
|
|
|
//检测端口
|
|
|
- detectionPort();
|
|
|
+ //detectionPort();
|
|
|
+ if (!PortInUse(9191))
|
|
|
+ {
|
|
|
+ MessageBox.Show("有依赖项启动失败,请重新启动客户端或联系管理员!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool PortInUse(int port)
|
|
|
+ {
|
|
|
+ Thread.Sleep(2500);
|
|
|
+ bool inUse = false;
|
|
|
+
|
|
|
+ IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
|
|
|
+ IPEndPoint[] ipEndPoints = ipProperties.GetActiveTcpListeners();
|
|
|
+
|
|
|
+ foreach (IPEndPoint endPoint in ipEndPoints)
|
|
|
+ {
|
|
|
+ if (endPoint.Port == port)
|
|
|
+ {
|
|
|
+ inUse = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return inUse;
|
|
|
}
|
|
|
}
|
|
|
}
|