How to check if a TCP port is free 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 TCP IP protocol for communication, it is better to know whether or not the port you want to use is free before the installation starts. Using Advanced Installer, you can make this check using the CheckTCPPort predefined custom action.

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


Dialog editorGo to the Dialog Editor page.

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

CheckFreeTCPPort dialog

Bind the port Edit control to the AI_BIND_TCP_PORT property. The Check TCP Port custom action gets the port that will be checked from AI_BIND_TCP_PORT property.

PortEdit control

Call the Check TCP Port custom action when the "Next" button is clicked. To do that, the "Next" button must publish an Execute custom action control event with "CheckFreeTCPPort" argument. Verify the return of the check and display a message if the port is used by another application. Do not go to the next dialog in the chain if the port is used. To display the message, create a new spawn dialog and publish a Display a specific child dialog control event.

CheckFreeTCPPort dialog next button events

Sample Project

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