使用inno setup安装时检查可用端口

时间:2013-07-05 09:17:02

标签: c# inno-setup

我正在尝试在inno设置中创建以下功能。

要求用户输入他们希望我的应用程序进行通信的端口。 一旦他们进入港口,他们就可以点击一个检查按钮。 此检查按钮将运行一些代码以查看安装机器上的端口是否可用。

到目前为止,我可以创建输入框,供用户输入他们想要测试的端口。我有以下代码来测试端口是否可用。

int port = 456; //<--- This is your value
bool isAvailable = true;

// Evaluate current system tcp connections. This is the same information provided
// by the netstat command line application, just in .Net strongly-typed object
// form.  We will look through the list, and if our port we would like to use
// in our TcpClient is occupied, we will set isAvailable to false.
IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
TcpConnectionInformation[] tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections();

foreach (TcpConnectionInformation tcpi in tcpConnInfoArray)
{
    if (tcpi.LocalEndPoint.Port == port)
    {
        isAvailable = false;
        break;
    }
}

Console.WriteLine("Port is available");

我的第一个问题是:是否可以从端口测试代码返回inno设置true或false值?如果它是假的,那么我需要让用户知道。

我的第二个问题是:端口测试代码是否正确?

我的第三个问题是:我是否正确地认为我可能需要在防火墙中打开该端口。

0 个答案:

没有答案
相关问题