Incorporating Custom Actions

Applies To: Windows 7, Windows Server 2003, Windows Server 2003 R2, Windows Server 2003 with SP1, Windows Server 2003 with SP2, Windows Server 2008, Windows Server 2008 Foundation, Windows Server 2008 R2, Windows Server 2012, Windows Vista

You can enhance the connection experience for your users by providing additional programs that start seamlessly during the connection to your service. You can use the Connection Manager Administration Kit (CMAK) wizard to include custom actions in your connection profiles to automatically start programs when users connect to your service. These custom actions can use programs that are already installed, or you can include the programs with your connection profile.

What custom actions are supported and when do they run?

Using the CMAK wizard, you can specify custom actions to run at nine points during the connection process. You can run:

  • Pre-init actions

  • Pre-connect actions

  • Pre-dial actions (for dial-up connections only) (for dial-up connections only)

  • Pre-tunnel actions (for VPN connections only) (for virtual private network (VPN) connections only)

  • Post-connect actions

  • Monitored actions

  • Disconnect actions

  • On cancel actions

  • On error actions

Pre-init actions

As soon as a user starts Connection Manager, it runs the pre-init actions specified in the connection profile. These actions are run before the Connection Manager logon screen appears.

Pre-connect actions

As soon as users click Connect, Connection Manager runs the pre-connect actions specified in the connection profile. These are run before Connection Manager establishes a connection to your service. For actions that relate specifically to dialing, use pre-dial actions. For actions that relate specifically to tunneling, use pre-tunnel actions, not pre-dial actions.

You cannot set up a pre-connect action that requires an interaction with your service. If interaction is required for part of the action, split the action into a pre-connect action and either a pre-tunnel or post-connect action, depending on the interaction requirements.

For example, recording information to a local log at the start of the logon process can be a pre-connect action, but if you want the log to post to your service, you might set up a separate upload program to be run as a post-connect, or disconnect action.

Pre-dial actions (for dial-up connections only)

Connection Manager runs pre-dial actions after users click Connect but before the computer starts to dial the connection to your service. Pre-connect actions run before pre-dial actions.

For example, pre-dial actions might include a program to change the telephone number for the connection profile, or they might include a program that affects how the profile dials the connection.

Pre-tunnel actions (for VPN connections only)

Connection Manager runs pre-tunnel actions after establishing a network connection to the remote access server but before establishing a tunnel. This type of action is available only if you set up VPN in your connection profile, and it will run only when users are using the VPN connection option.

For VPN connections, set up all custom actions that require interaction with an Internet server as pre-tunnel actions, because Connection Manager has limited access to an Internet server after a tunnel is established.

For example, this might be a program that verifies user credentials for accessing a corporate server behind a firewall or that checks the expiration dates of client certificates.

For direct VPN connections, Connection Manager runs both pre-connect and pre-tunnel actions before connecting.

Post-connect actions

Connection Manager runs post-connect actions after establishing a connection or, if using a VPN connection, after establishing the tunnel. Each post-connect action that you specify in the CMAK wizard runs every time the user connects to your service, whether the connection is a dial-up connection or a VPN connection.

As an example, in the CMAK wizard Custom Actions pane, you might see the following built-in post-connect action:

  • Download phone-book updates. If you set up the connection profile to automatically download phone book updates, Connection Manager includes this post-connect action which sends a phone book request to the server running Phone Book Service (PBS). The server compares the client phone-book version with the most recent files available at the server and then downloads any available phone-book updates. The next time the user starts Connection Manager, the updated access numbers are available. You must provide the name of the phone book and the URL of the PBS server in order to set up this custom action. For more information on phone book updates, see Connection Point Services and Connection Manager.

Other selections in the wizard that result in post-connect actions are routing table updates, applying proxy settings, and updates to the VPN server file.

Monitored actions

Connection Manager runs monitored actions after establishing a connection and, for a VPN connection, after establishing the tunnel. Each monitored action that you specify in the CMAK wizard runs every time the user connects to your service, whether the connection is a dial-up connection or a direct connection. Monitored actions cause the connection to end after specified programs have ended. For example, if you want to automatically run an e-mail program, and then automatically end the connection when the user quits the e-mail program, you must set up e-mail as a monitored action.

Monitored actions are similar to post-connect actions, except that:

  • All monitored actions must be .exe files, because monitored actions are run asynchronously. A dynamic-link library (DLL) runs synchronously, so it cannot be run as a monitored action.

  • Connection Manager automatically monitors the status of all monitored actions and starts the disconnect sequence when the last monitored action closes.


When the last monitored action closes, Connection Manager provides a prompt to allow the user to override the disconnect sequence. The user can click Stay Online to prevent disconnection, click Disconnect Now to disconnect immediately, or do nothing to let the connection close automatically after 30 seconds have elapsed.

As with post-connect actions, you must provide the appropriate information for each monitored action specified in the connection profile, including the application to run, whether to include the application in the connection profile, and any command-line parameters that you want to run with the application. Unlike post-connect actions, you do not specify a descriptive name for a monitored action.


Specify only applications that are complete program files. You can include only one file for each monitored action. If you specify an application that requires other files or is a self-extracting executable (.exe) file as a monitored action, these files might cause the program or connection to be interrupted. If a monitored action requires any files in addition to the executable file, you should specify them as Additional Files in the CMAK wizard. These files will be installed with the connection profile but not run. For more information on how to include these support files in the connection profile, see Including Additional Files.

You can specify a variety of applications as monitored actions. For example, you might want to include a commercially available e-mail application, a customized stock-ticker application, and an internal accounting application. The CMAK wizard can specify all three types of applications. You can also select whether the application for each monitored action is to be included in your connection profile.


If the application is one that users already have installed on their computers, do not include it in the connection profile. Doing so will increase the size of your connection profile and might cause problems on the users' computers.

Disconnect actions

Connection Manager runs disconnect actions immediately before disconnecting from your service. You can use a disconnect action for routine administration. For example, you might set up a custom action to collect status information from your service, such as total minutes online (if this information is tracked by your service). This information can then be displayed for the user.


Disconnect actions will run even if the disconnect was not initialized by Connection Manager. For example, if the user's connection is terminated by a disruption in telephone service, Connection Manager will attempt to run the disconnect actions specified in the connection profile after the unexpected termination.

On cancel actions

As soon as users click Cancel during a connection attempt, Connection Manager runs the on cancel actions specified in the connection profile. On cancel actions do not run if the user clicks the Cancel button to close the Connection Manager program. You might use on cancel actions to reverse any pre-init actions you specified in the connection profile.

On error actions

Connection Manager runs on error actions whenever an error occurs during the connection. You might use on error actions to collect information about the error for later support.

What types of programs can be used as custom actions?

A custom action can be:

  • A dynamic-link library (DLL)

  • An executable file such as a .bat, .exe, or .cmd file

  • A shell-executable file, such as a .txt or .doc file

Only DLLs run synchronously, meaning that Connection Manager starts the action and then waits for the function to return before continuing. The first argument, specified as the Parameters on the Add/Edit Custom Actions page of the CMAK wizard, is the function name within the DLL to call. The syntax for each of these custom actions is:

    [IN] HWND hWndParent
    [IN] HINSTANCE hinstDll
    [IN] LPCSTR pszCommandLine
    [IN] DWORD dwReserved

Supported DLL parameters are:

Parameter Result


Handle to the Connection Manager logon dialog box or NULL; used as the parent window for any user interface displayed by the custom action.


Handle to the instance of this DLL.


String pointer to the command-line arguments.


Reserved for future use.

DLLs often have a comment (entered in the description field of the CMAK wizard) that appears while it is being run. This comment has the form Running Custom Action Description. The Connection Manager window is frozen and does not accept input while this type of action runs.

Custom action DLLs require a return value. If the return value is less than 0, the DLL call failed (SUCCEEDED macro returns False). In the case of a failure, an error message (including the return value) is displayed in the form "Custom Action Description failed return value." If a pre-init, pre-dial, pre-connect, pre-tunnel, or post-connect DLL action fails, the connection attempt is ended.

The DLL is unloaded after the function call.


For .dll files that require extended times for the program to run, you should implement WM_PAINT messages in the .dll file to ensure that graphics are not disrupted by user actions.


You must provide the exact name of exported functions when building custom action DLLs. If you are using a language that changes the exported name (such as C++), you can use a .def file to preserve the exported function names.

Including executable files

This type of custom action is run asynchronously, which means that Connection Manager starts the executable, including any command-line parameters, and continues without waiting for the process to exit. No comment appears in the Connection Manager status pane while these programs are run.

Including shell-executable files

These actions run asynchronously. Each shell-executable file needs to be opened by a particular program.

If this program is not included with Windows, you might need to include it with your connection profile.

How to specify a custom action

On the CMAK wizard Custom Actions page, click New to add a custom action or Edit to edit an existing custom action. A dialog box will appear, where you must provide the following information for each custom action:

  • Description: Provide a short description of the program to run. If you do not provide a description, the CMAK wizard uses the program name (specified in Program to run) as the description.

  • Program to run: Specify the file name of the program or file, including the file name extension (such as .dll, .exe, .bat, or .cmd).

  • Parameters: Specify any command-line parameters that you want to run with the program. The following special command-line parameter macros are supported:

    Macro Replaced with


    The service name of the profile.


    The user-name prefix used for this connection.


    The user-name suffix used for this connection.


    The user name, without any specified realm user-name prefix or suffix.


    The location and file name of the active Connection Manager profile (.cmp) file.


    The path to the folder containing the profile.


    The domain for the connection.


    The user name for the Internet connection.


    A value that identifies the connection type, 0, 1 or 2.

    0 = dial-up

    1 = VPN

    2 = dial-up then tunnel


    The full path to the phone book file.


    The full path to the phone book file used for the VPN portion of this connection.


    The service name or remote access entry name for the dial-up connection.


    The service name or remote access entry name for the tunnel connection.


    A Boolean value that is 1 if this dial attempt is an automatic redial, or 0 if not an automatic redial.


    The description for the phone number in the phone book.


    The Win32 error code.


    The origin of the last error.


    The location settings selected in the Use settings for box.


    The IP or DNS address of the VPN server, if any.


    The IP address of the computer on which the Connection Manager profile is installed.


    The IP address of the remote access server, if any.


    A Boolean value, used in a custom action to determine whether or not to display a user interface. You can incorporate this macro in a custom action to display an interactive user interface (such as an error message) only when Connection Manager is running in an interactive state, and to take other action (such as failing gracefully without an error message) when Connection Manager is running in a non-interactive state. This macro was designed to be used in conjunction with the Program interacts with the user check box. For example, if you deselect Program interacts with the user, you should add the %interactive% macro to the custom action parameters so that the custom action can behave according to the state in which Connection Manager is run. This might require modification to the custom action itself.

When parameters are specified, Connection Manager reads the parameter string and passes it to the pszCommandLine parameter of the .dll or sends it as part of the command line to an executable (available through the Windows API GetCommandLine).

If the custom action is a DLL, then the first token of the parameter string is the function entry point to call. This token is removed from the parameters before the string is passed to the DLL (so the pszCommandLine string does not start with the .dll entry point name as the first parameter). When creating the DLL, ensure that the exported name of the DLL matches the name specified as the first parameter, as name decoration can result in different names. (For example, in C++, name decoration can cause the exported name to be different from the actual function name.)

If you use the macros shown in the previous table, Connection Manager replaces them with the actual run-time information for the parameter. For instance, if you wanted a custom action to collect information about which users are using which POPs, you might create a .dll (or other executable) for this purpose, and Connection Manager could pass it information such as user name (using the %UserName% macro), realm information (using the %Prefix% or %Suffix% macro), and POP name (using the %PopName% macro). To do this, in Parameters, type the following: LogUserAndPopToServer %UserPrefix% %UserName% %UserSuffix% %PopName% %AutoRedial%

Depending on the user connection method, the information passed to the DLL might be:

NULL jobrown "Seattle 28,800" 0

Connection Manager cannot denote a null pointer in a string, so it passes the string NULL (which it passes for all undefined parameters). Only use quotes when a parameter contains spaces, such as "Seattle 28,800". The number variables have to be parsed from the string. If you are using an executable other than a DLL, the function name (in the above example, LogUserAndPopToServer) is not required.

  • Action Type: Specify the time at which the action is performed by selecting Pre-init, Pre-connect, Pre-dial, Pre-tunnel, Post-connect, Monitored, Disconnect, On cancel, or On error.

  • Run this custom action for: Specify the kinds of connections for which this custom action should be run. You can choose to run this action for All connections, All connections that involve dial-up, All connections that involve a tunnel, Connections that use only a tunnel, or Connections that use only dial-up.

  • Include the custom action program with this connection profile. Select this option to include the program with the connection profile. If the program you want to run is not part of a standard Windows installation or is not otherwise already available to your users, you should include the program in your connection profile. The custom action program is installed in the connection profile folder.

  • Program interacts with the user. This check box is selected by default. If this check box is selected, Connection Manager will not run the custom action if it is in a non-interactive state. If this check box is not selected, a program called by the custom action that interacts with the user will halt the connection process indefinitely, waiting for a response from the user. For more deterministic behavior, you can deselect this check box and use the %interactive% macro.

Specify only programs that are complete program files. You can include one program file per custom action. If any non-executable files are required to support a custom action, you should include them as additional files, not as custom actions. These additional files should be files that are installed with the connection profile but do not have to be run. For more information on how to include these support files in the connection profile, see Including Additional Files.


If a custom action runs when users log on to Windows, the custom action runs with system permissions. You should ensure that any custom actions that you enable do not pose unintended security risks.


Custom actions are run in the order shown in the CMAK wizard.


Not all system macros are supported on all Windows operating systems.


By default, custom actions are not run when a profile is used to log on to Windows. For more information about whether to enable custom actions for use when logging on to Windows, see Incorporating Connection Manager with Logon Security.


If you want settings not found in the Connection Manager macros, other settings can be accessed programmatically through remote access Application Programming Interfaces (APIs), which are documented in the Remote Access (

Additional references