How to get a free TCP port by using a custom action

ImportantThe following article uses options that are available starting with the Enterprise edition and project type.

If you install a server application that uses a TCP IP protocol for communication is better to know before installation starts that the port you want to use is free. Using Advanced Installer you can get a free TCP port using GetFreeTCPPort predefined custom action.

Custom actions Go to the Custom Actions page and add the predefined UI Custom Action "Get free TCP Port".

GetFreeTCPPort

Dialog editorGo to the Dialog Editor page.

New dialogCreate a new dialog called "GetFreeTCPPort", added after "WelcomeDlg" in the dialogs tree.

CheckFreeTCPPort dialog

Bind the port edit control to the AI_SEARCH_TCP_PORT property. The Get free TCP Port custom action gets the starting port from which the search starts from AI_SEARCH_TCP_PORT property. Bind the static text controls to the RESULT and RET properties.

Select the "Get" button and the following "Published events" as in the image below:

GetFreeTCPPort dialog next button events

Sample Project

NoteYou can find a small sample Advanced Installer project implementing the above functionality here.