# Custom Executes

Last Modified: February 10, 2020

Custom executes are executables or batch scripts that can be run during a package transaction.

There are six types of custom executes:

1. Pre Install: Runs before a single package installs.
2. Post Install: Runs after a single package installs.
3. Post All Install: Runs after all packages in an install transaction have completed.
4. Pre Uninstall: Runs before a single package uninstalls.
5. Post Uninstall: Runs after a single package uninstalls.
6. Post All Uninstall: Runs after all packages in an uninstallation transaction have completed.

## Root and Relative Path

Root is the root directory where the custom execute will be located. A relative path from the root to the executable can be specified in the relative executable path. The relative executable path is either just the executable name, if the executable is located immediately under the root, or a relative path from the root to the executable.

## Examples

Example 1

Root: [Program Files (64-bit)]
Relative Executable Path: foo.exe


Typical path: C:\Program Files\foo.exe

Example 2

Root: [Program Files (64-bit)]
Relative Executable Path: relative\path\foo.exe


Typical path: C:\Program Files\relative\path\foo.exe

## Arguments

Every custom execute can define arguments to be passed into the executable. These can be literal arguments or macros surrounded by the % character.

## Macros

Arguments can contain macros surrounded by the % character. Macros will be replaced when invoking the custom execute. In the example below, %desktop% will be replaced with the path to the public desktop and %rebootpending% will be replaced with a 1 or 0 indicating whether a reboot is required.

-open %desktop%\file.txt -reboot %rebootpending%

Refer to Installation Target Roots for File Packages in the NI Package Manager manual for a list of supported directory macros.

## Quotations

If an argument contains spaces, it needs to be surrounded by quotation marks so that it is treated as one argument. In the example below, the path, C:\path with spaces\, will be passed to the executable as one argument instead of three separate arguments.

-open "C:\path with spaces\"

## Options

There are three options that can be checked for each custom execute.

1. Wait to complete: The transaction will wait for the custom execute to complete.
2. Ignore errors: The transaction will not fail if the custom execute returns non-success.
3. Show console window: A console window will be shown for command line executables and batch scripts.

## Post All Custom Executes

Consider package A that depends on package B. If both packages have a post all custom execute with the exact same information (i.e., same executable name and arguments), installing package A will invoke only one of the custom executes.

## Calling cmd.exe

A custom execute can invoke a Windows CMD shell by calling cmd.exe and specifying the /c option. The custom execute invokes the specified command/executable program passed as an additional argument.

Example 1

Root: [System (32-bit)]
Relative Executable Path: cmd.exe
Arguments: /c "%Temp%\MyTempFile.bat"


Calls a batch file installed by the package to the [Temp] directory.

Example 2

Root: [System (32-bit)]
Relative Executable Path: cmd.exe
Arguments: /c ""%Program Files_64%\MyTempFile.bat" "parameter 1" "parameter 2""

Calls a batch file located in the [Program Files (64-bit)] directory and passes additional parameters.
Note

Use additional quotation marks when passing this type of argument.

## Debugging Custom Executes

If NI Package Manager cannot locate the executable specified by the root and relative path, it will display the following error message:

An error occurred while installing package 'package-name'.

Call the executable using cmd.exe. When calling cmd.exe, enable the 'Show Console Window' option, and specify /k instead of /c to see any status reports from cmd.exe. Enter the exit command to close the console window when debugging with the /k option.